Good Evening,
I am using the following code to generate a csv file which works great except it is escaping all the comma’s from the query when it writes the file.
<div>
<div class="pt-2 row">
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
<input type="submit" class="btn btn-link" name="export_csv_btn" value="Export Data into CSV" />
</form>
</div>
</div>
<?php
if(isset($_POST['export_csv_btn'])){
// open the file "products.csv" for writing
$file = fopen('c:/wamp64/www/export/products.csv', 'w');
// save the column headers
fputcsv($file, array('Id', 'Name', 'Categories', 'EAN', 'Quantity'));
// Product data.
//query the database
$query = 'SELECT id, name, categories, ean, quantity FROM tbl_temp_products';
if ($rows = mysqli_query($conn, $query))
{
// loop over the rows, outputting them
while ($row = mysqli_fetch_assoc($rows))
{
fputcsv($file, $row);
}
// free result set
mysqli_free_result($result);
}
// Close the file
fclose($file);
}
?>
The main problem is with the category field.
In the database it is stored as 123,456 but when the file is written it is written as 123456
Is there a work around to escape the comma in this field?
Thanks