Double Data in CSV
Posted: Mon Jan 18, 2010 4:13 pm
I have a script that exports data from a MySQL database into a CSV file. The only problem is that it is doubling the data from each field.
So if the data in cell A is supposed to be 'One Hundred Forty One' then it will put that in Cell 'A' and 'B'
Here is the Code:
So if the data in cell A is supposed to be 'One Hundred Forty One' then it will put that in Cell 'A' and 'B'
Here is the Code:
Code: Select all
$a=0;
$check = $_POST['check'];
$number = count($check);
$fields = array('id', 'category', 'manufacturer', 'pagename', 'retailprice', 'salesprice', 'upc','sku', 'caption', 'image');
$fp = fopen('C:/wamp/www/Work/Upload/Files/csv/export/export' . ' ' . date('Y-m-d') . '.csv', 'w');
fputcsv($fp, $fields);
while ($a < $number)
{
$sql = 'SELECT pages.id, category.cat, manufacturer.manu, pages.pagename, pages.retailprice,
pages.salesprice, pages.upc, pages.sku, pages.caption, image.name FROM pages
INNER JOIN category ON pages.categoryid = category.id
INNER JOIN image ON pages.imageid = image.id
INNER JOIN manufacturer ON pages.manufactureid = manufacturer.id WHERE pages.id = "'. $check[$a] .'"';
$result = mysqli_query($link, $sql);
$row = mysqli_fetch_array($result);
fputcsv($fp, $row);
++$a;
}
fclose($fp);