施用fputcsv导出mysql查询内容出现两次

WBOY
Release: 2016-06-13 12:58:07
Original
838 people have browsed it

使用fputcsv导出mysql查询内容出现两次

<br />
<?<br />
header('Content-Type: application/vnd.ms-excel;charset="gbk"');<br />
header('Content-Disposition: attachment;filename="user.csv"');<br />
header('Cache-Control: max-age=0');<br />
<br />
$fp = fopen('php://output', 'a');<br />
 <br />
$head = array('仓库', '编码', '名称', '规格', '数量', '单位');<br />
<br />
fputcsv($fp, $head);<br />
// 计数器<br />
$conn = mysql_pconnect("localhost",'root','root');<br />
mysql_select_db("jhdb",$conn);<br />
$sql = "select b.name,a.Code,c.cName,c.cStd,a.num,c.cUnit from jh_kc a,jh_ck b,jh_inventory c where a.Code=c.Code and a.ckid=b.id and a.ckid=".$_REQUEST["ckid"];<br />
<br />
$result = mysql_query($sql,$conn) or die(msgbox("SQL出错:".$sql));<br />
while($myrow = mysql_fetch_array($result,MYSQL_BOTH))<br />
{<br />
	fputcsv($fp, $myrow);<br />
}<br />
mysql_free_result($result);<br />
<br />
?><br />
Copy after login

输出的csv文件内容会重复一次,结果如下:

仓库 编码 名称 规格 数量 单位
零配件仓库 零配件仓库 20101001 20101001 塑壳 H-3A 塑壳 H-3A PE白 PE白 37 37 斤 斤
零配件仓库 零配件仓库 20101003 20101003 塑壳 H-3A 塑壳 H-3A PP白 PP白 320 320 斤 斤


------解决方案--------------------
MYSQL_BOTH 是双键格式输出吧?
------解决方案--------------------
while($myrow?=?mysql_fetch_row($result))

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template