Tema: TXT tabulado
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/08/2009, 08:27
pabletein
 
Fecha de Ingreso: julio-2008
Mensajes: 45
Antigüedad: 18 años, 3 meses
Puntos: 1
TXT tabulado

Buenas a todos!!!
Aqui con un problema nuevo: necesito exportar los mails y nombre de una base de datos como txt tabulado . Buscando por la red encontre la solucion. Despues, como no era exacta, la retoque un poco y quedo como queria ... excepto por lo siguiente: en vez de ponerme un dato y despues tabular, primero tabula y despues pone el primer dato.
He aqui el codigo a ver si alguien entiende un poco mas esto :
Código PHP:
// Query DB 
$select = "SELECT email, nombre FROM contactos, $tabla  
         WHERE $tabla.recibe = 1 AND contactos.ID = $tabla.ID_contactos"
; 
          
$export = mysql_query($select, db_link); 
$row_export = mysql_fetch_assoc($export); 
$fields = mysql_num_fields($export); 
//echo $select ; 
// Is there any data or should we call it quits? 
$num_rows = mysql_num_rows($export); 
if (!
$num_rows) 
{ 
   echo 
"<h1 style=\"font-family: Arial, Helvetica, sans-serif\">Sorry, no data available for export.</h1>"; 
   exit(); 
} 
 
// Set headers 
 
//header("Content-type: application/vnd.ms-excel"); 
header("Content-Type: application/force-download"); 
//header("Content-Disposition: attachment; filename=DataExport_". date("mdy_Gis", $time) .".csv; size=$size_in_bytes"); 
header("Content-Disposition: attachment; filename=Recipientes_". date("mdy_Gis", $time) .".txt; size=$size_in_bytes"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
 
// Process rows 
$count = mysql_num_fields($export); 
/* 
for ($i = 0; $i < $fields; $i++) 
{ 
   $header .= mysql_field_name($export, $i) . "\t"; 
} 
*/ 
if ($num_rows) 
{ 
   
mysql_data_seek($export,0); 
} 
 
while(
$row = mysql_fetch_row($export)) 
{ 
   
$line = ''; 
   foreach(
$row as $value) 
   { 
      if ((!isset(
$value)) OR ($value == "")) 
      { 
         
$value = ""; 
      }  
      else 
      { 
         
//$value = str_replace('"', '""', $value); 
         //$value = '"' . $value . '"' . "\t"; 
         ///TABULA ENTRE MAIL Y NOMBRE 
         
$value = $value ."\t"; 
      } 
      
$line .= $value; 
   } 
   
$data .= trim($line)."\n"; 
}  
 
$data = str_replace("\r","",$data); 
echo 
$header."\n".$data; 
?> 
Ojala alguien entienda que hacer con esto!!!

Muchasd gracias!!