Using fputcsv to export MySQL query content appears two times
Header (' content-type:application/vnd.ms-excel;charset= ' GBK "');
Header (' content-disposition:attachment;filename= ' user.csv "');
Header (' cache-control:max-age=0 ');
$fp = fopen (' php://output ', ' a ');
$head = Array (' Warehouse ', ' code ', ' name ', ' spec ', ' Quantity ', ' unit ');
Fputcsv ($fp, $head);
Counter
$conn = Mysql_pconnect ("localhost", ' root ', ' root ');
mysql_select_db ("Jhdb", $conn);
$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.ck Id=b.id and a.ckid= ". $_request[" Ckid "];
$result = mysql_query ($sql, $conn) or Die (MsgBox ("SQL error:". $sql));
while ($myrow = Mysql_fetch_array ($result, Mysql_both))
{
Fputcsv ($fp, $myrow);
}
Mysql_free_result ($result);
?>
The contents of the output CSV file are repeated once and the results are as follows:
Warehouse Code name Specification Quantity unit
Spare parts warehouse Spare parts warehouse 2010100120101001 plastic shell h-3a plastic shell h-3ape White PE white 3737 commonly
Spare parts warehouse Spare parts warehouse 2010100320101003 plastic shell h-3a plastic shell H-3app White pp white 320320 commonly
------Solution--------------------
Mysql_both is the double bond format output?
------Solution--------------------
while ($myrow? =?mysql_fetch_row ($result))