dovresti provare con una struttura di questo tipo... devi stare attento però al charset, dipende come salvi i dati nel DB, ev. cambi in ISO-8859-1:
Codice PHP:
$ris = mysql_query ("SELECT * FROM prima ORDER BY classe");
// crei l'header del file
$string = "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<title>Title</title>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
</head>
<body>
<table cellspacing='1' cellpadding='2' border='1'>
";
// crei le colonne
$fieldnames = array();
$fieldnames[] = "Field1";
$fieldnames[] = "Field2";
$fieldnames[] = "Field3";
// apri riga
$string .= "<tr>";
// loop per le celle/colonne
foreach($fieldnames as $fieldname) {
$string .= "<td>$fieldname</td>";
}
$string .= "</tr>";
// loop delle righe
while ($riga = mysql_fetch_row($ris)) {
$string .= "<tr>";
$string .= "<td>Cell1</td>";
$string .= "<td>Cell2</td>";
$string .= "<td>Cell3</td>";
$string .= "</tr>";
}
$string .= "
</table>
</body>
</html>
";
print $string;