
Originariamente inviata da
daduz
ciao las e intanto grazie anche a te, ho fatto come dici tu e nello specifico
codice HTML:
$table = 'bp';
$filename = 'bpfile';
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
//$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$result = mysql_query("select mail,telefono,fax FROM ".$table."");
//echo $result;
//exit;
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field']."; "; //ELIMINO INTESTAZIONE COLONNE
$i++;
}
}
$csv_output .= "\r\n";
$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."; ";
}
$csv_output .= "\r\n";
}
file_put_contents($filename.".csv",$csv_output);
ma il file csv che mi esce non riporta intestazione colonna
e come valori solo la prima colonna a sx con valore 1 alla prima riga utile e 2 alla seconda...
non pesca dal db suppongo
grazie per la pazienza!
ho fatto dei progressi!
cosi mi funziona ma non mi scrive l' intestazione delle colonne..
suppongo l' errore sia nella riga
$csv_output .= $row['Field']."; "; //ELIMINO INTESTAZIONE COLONNE
grazie!
codice HTML:
$table = 'bp';
$filename = 'bpfile';
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
//$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$result = mysql_query("select mail,telefono,fax FROM ".$table."");
//echo $result;
//exit;
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field']."; "; //ELIMINO INTESTAZIONE COLONNE
$i++;
}
}
$csv_output .= "\r\n";
//$values = mysql_query("SELECT * FROM ".$table."");
$values = mysql_query("select mail,telefono,fax FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."; ";
}
$csv_output .= "\r\n";
}
file_put_contents($filename.".csv",$csv_output);