我有这段代码可以将 MySQL 数据导出到 CSV 文件,但是当我回显结果时,它只显示数据库中的 1 行,即使我在 PHP My Admin 中运行 SQL,它也会显示大约 29 行。
它只是生成一个空白的 CSV 文件
$sql="select description, jobreceived, timebookedfor, bookedfor,
site_contact, site_address, invoice_contact, invoice_address,
quotedprice, cleardowndetails, notes, mo_number from jobs ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
$filename="jobs.csv";
$file=fopen($filename,"w");
//$output="sequence,firstname,surname,email,membertype\n";
fwrite($file,$output);
while($result=mysql_fetch_array($rs))
{
echo $result["description"].','.$result["jobreceived"].'<br>';
//$output=$result["sequence"].",".$result["name"].","
.$result["email"].",".$result["country"]."\n";
$output=proper($result["description"]).",".$result["jobreceived"]
."\r\n";
fwrite($file,$output);
}
fclose($file);
function proper($string)
{
$first=strtoupper(substr($string,0,1));
$rest=strtolower(substr($string,1));
$result=$first.$rest;
return $result;
}