I have MySql data base and web site, in the web i show database values in table. I made that CSV exports the specify database model(table).
`$this->view->table = $model->info('name');
$is_csv = $this->_getParam('csv');
if ($this->_request->isPost() && $is_csv) {
$file1 = 'Baudų sąrašas '.$date_from.' iki '.$date_to.'.csv';
$fp = fopen('php://output', 'w+');
if ($date_from) {
$select->where("date >= ?", $date_from . ' 00:00:00');
}
if ($date_to) {
$select->where("date <= ?", $date_to . ' 23:59:59');
}
$data = $model->fetchAll($select);
foreach ($data as $fields) {
fputcsv($fp, $fields->toArray());
}
fclose($fp);
if ($file1 !== false) {
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="' . $file1 . '"');
exit;
}
}`
And the HTML that calls it:
form method="post">
<div class="control-group pull-right">
<input type="hidden" name="table" value="<?php echo $this->table ?>" />
<button type="submit" class="btn" name="csv" value="csv"><?php echo Core_Locale::translate('CSV')?></button>
</div>
</form>
Now i want to take not from data base, but from function wich has Join's to the database, but when i use
return $this->getAdapter()->fetchAll($select); it gives error non object and when i write return $this->fetchAll($select); it gives me as data base data as from function...
Do any may have some clue how to do this?