I have a php file. This file is a copy of a feed file inside Opencart and its like this:
<?php
public function index() {
$ids = $this->db->query("select * from t_product where quantity>0");
foreach ($ids->rows as $id) {
//Inside here i create php variables, each one includes information like description, url etc and at the end i place it here:
$myrow = $id . ',' . $model . ',' . $name . ',' . $product_url;
}
$this->response->addHeader('Content-type: text/csv');
$this->response->setOutput($myrow);
}
?>
When i use the above code, then when i run the php file in browser, i get a php file downloaded that has all my data that i need. My question is how could i export this in csv format?
I tried code from: http://code.stephenmorley.org/php/creating-downloadable-csv-files/ with no success at all. Any ideas?
Also i somewhere read that i have to escape single quotes, double quotes and commas. How do i do this?
EDIT:
I also tried this:
<?php
public function index() {
$ids = $this->db->query("select * from t_product where quantity>0");
$fp = fopen('php://output', 'w');
foreach ($ids->rows as $id) {
//Inside here i create php variables, each one includes information like description, url etc and at the end i place it here:
$myrow = $id . ',' . $model . ',' . $name . ',' . $product_url;
fputcsv($fp, $myrow);
}
fclose($fp);
$this->response->addHeader('Content-type: text/csv');
$this->response->setOutput($fp);
}
?>
with no success!
.csv?