我创建了一个带有左连接选择查询的 csv 导出脚本。它在具有相同数据的 Localhost 服务器(Windows 8)上运行良好,但在 Web 服务器(Linux)上运行不佳。
每行都在本地主机上连续导出。但是,具有相同 MySQL 数据的相同查询从 Web 服务器导出错误。
例如,在描述列之后的第 261 行,它被分成新的行,第 261 行的剩余列。从第 263 行开始,数据导出正常,直到第 415 行。在描述后再次被打破为新的 Excel 行。然后再次导出正常直到 1133。在描述为新的 Excel 行后再次中断。
我无法理解这个问题。脚本有什么问题?
$values = mysql_query("SELECT
t1.inqty, IFNULL(t2.outqty, '0') outqty, (IFNULL(t1.inqty,'0') - IFNULL(t2.outqty, '0')) totalHand,
t1.serialno,
(SELECT projectname FROM projects WHERE t1.project_id = projects.project_id) AS ProjectName,
TRIM(t1.productid),
TRIM(t1.description),
TRIM(t1.revisionstate),
TRIM(t1.remarks),
(SELECT username FROM wms_users WHERE t1.userid = wms_users.id) AS UserName,
(SELECT cusname FROM customerinfo WHERE t1.cus_id = customerinfo.cus_id) AS CustomerName,
t1.inserteddate
FROM
(
SELECT *, SUM(in_quantity) inqty FROM stockin GROUP BY serialno
) t1 LEFT JOIN
(
SELECT serialno, SUM(out_quantity) outqty FROM stockout GROUP BY serialno
) t2
ON t1.serialno = t2.serialno
");
$headings = array('INQTY','OUTQTY','TOTAL IN HAND','SerialNo','Project Name','ProductID','Description','Revision State','Remarks','Username','Customer Name','Inserted Date');
$i = 0;
foreach ($headings as $heading) {
$csv_output .= $heading . ",";
$i++;
}
$csv_output .= "\n";
while ($rowr = mysql_fetch_row($values)) {
for($j = 0; $j < $i; $j++) {
$csv_output .= $rowr[$j] . ",";
}
$csv_output .= "\n";
}
ob_end_clean();
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
//header("Content-type: text/csv");
header('Content-Length: ' . strlen($csv_output) );
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;