ragazzi, una domanda, magari è idiota ... ma non capisco come mai a video mi stampa due volte per ogni campo .... ecco il codice
codice:
<?php
$link = mysql_connect('localhost:/mysql/data/miodb', 'user', 'pw');
mysql_select_db('miodb');
$sql = "SELECT a.cognome, a.nome, a.citta, a.telefono, a.email, a.idcitta, b.citta as cittaisc FROM iscritto a, citta b where a.idcitta = b.idcitta order by b.citta, a.cognome, a.nome";
$result = mysql_query($sql);
$numfields = mysql_num_fields($result);
$filename = "tmp/iscritti_".time().".csv";
$handle = fopen($filename, 'w+');
fputcsv($handle, array('cognome','nome','citta','telefono','email','cittaisc'));
echo
"<table width='80%' border='1' cellspacing='1' cellpadding='3'>
<tr>";
for ($i=0; $i < $numfields; $i++)
{
echo '<th>'.mysql_field_name($result, $i).'</th>';
}
echo "</tr>\n";
while ($row = mysql_fetch_array($result))
{
echo '<tr><td>'.implode($row,'</td><td>')."</td></tr>\n";
fputcsv($handle, array($row['cognome'],$row['nome'], $row['citta'], $row['telefono'], $row['email'], $row['idcitta'], $row['cittaisc']));
}
echo "</table>\n";
fclose($handle);
mysql_close($link);
?>