Ciao a tutti, ho un codice che funziona perfettamente, attraverso una
query, esporta in un file excel determianti dati... il problema è che se
un campo del DB è vuoto, non viene creata la relativa colonna per il
record considerato... quindi il record non risulta incolonnato con gli
altri records (quelli che hanno appunto il campo nel DB)
come dovrei modificare il seguente codice?
Codice PHP:
$select = "..."
$export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error(
) );
$fields = mysql_num_fields ( $export );
for ( $i = 0; $i < $fields; $i++ )
{
$header .= mysql_field_name( $export , $i ) . "\t";
}
while( $row = mysql_fetch_row( $export ) )
{
$line = '';
foreach( $row as $value )
{
if ( ( !isset( $value ) ) || ( $value == "" ) )
{
$value = "\t";
}
else
{
$value = str_replace( '"' , '""' , $value );
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim( $line ) . "\n";
}
$data = str_replace( "\r" , "" , $data );
if ( $data == "" )
{
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=Report_Disdette.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
Grazie