我正在将查询结果导出到 csv 文件中。代码如下所示:
$query = "SELECT DATE(punchdetails.punchin) as punchday,punchdetails.punchin,punchdetails.punchout,employeedetails.employeename
FROM punchdetails join(employeedetails) ON punchdetails.employeeid=employeedetails.employeeid
AND punchdetails.employeeid=$employeeid AND DATE(punchdetails.punchin)=$fromdate";
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
ini_set('display_errors',1);
$private=1;
error_reporting(E_ALL ^ E_NOTICE);
$select_c = mysql_query($query);
while ($row = mysql_fetch_array($select_c))
{
$intime = strtotime($row['punchin']);
$mysqlintime = date( 'H:i:a', $intime );
$outtime = strtotime($row['punchout']);
$mysqlouttime = date( 'H:i:a', $outtime );
$result.=$row['employeename'].','.$row['punchday'].','.$mysqlintime.','.$mysqlouttime;
$result.="\n";
echo $result;
}
当我执行查询时,它会正确返回记录。但是当我将查询结果下载为 csv 文件时,记录会重复。我得到如下所示的结果 csv 文件数据:
Sonu,2013-09-26,10:55:am,11:12:am
Sonu,2013-09-26,10:55:am,11:12:am
Kristo,2013-09-26,11:23:am,11:24:am
我没有得到什么问题。有人可以帮我解决这个问题吗?提前致谢。