Perchè mi compare questo messaggio:
"Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\project\Excel\save.php on line 14" ?
Devo usare $query?Codice PHP:$query = "SELECT ...";
$result = mysql_query($query);
if (!$result) {
die("Errore nella query $query: " . mysql_error());
}
if(mysql_num_rows($result) != 1) {
die("l'ID passato via GET è errato");
}
list(
$project_name,...) = mysql_fetch_row($result);
$conn=mysql_connect('localhost','root','');
$db=mysql_select_db('excel',$conn);
$filename = "prova.xls"; // File Name
// Download file
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
$result = mysql_query('select name,work from info');
// Write data to file
$flag = false;
while ($row = mysql_fetch_assoc($result)) {
if (!$flag) {
// display field/column names as first row
echo implode("\t", array_keys($row)) . "\r\n";
$flag = true;
}
echo implode("\t", array_values($row)) . "\r\n";
}
Ultima modifica di Valeria89; 02-07-2015 a 16:17
Visto che si tratta della riga di intestazione, puoi inserirla staticamente usando come separatore "\t".
Occhio che le funzioni mysql non saranno più supportate nelle nuove versioni di PHP, sarebbe il caso di iniziare ad usare le funzioni mysqliCodice PHP:$query = "SELECT ...";
$result = mysql_query($query);
if (!$result) {
die("Errore nella query $query: " . mysql_error());
}
if(mysql_num_rows($result) != 1) {
die("l'ID passato via GET è errato");
}
list(
$project_name,...) = mysql_fetch_row($result);
$conn=mysql_connect('localhost','root','');
$db=mysql_select_db('excel',$conn);
$filename = "prova.xls"; // File Name
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
$result = mysql_query('select name,work from info');
//qui i nomi delle colonne
echo "colonna1 \t colonna2 \t colonna3 \r\n";
while ($row = mysql_fetch_assoc($result)) {
echo implode("\t", array_values($row)) . "\r\n";
}
![]()
Ultima modifica di lucavizzi; 08-11-2016 a 13:20 Motivo: funzioni deprecate