1

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?

1 Answer 1

0

This is not the exact answer for your question, but why don't you try this..

SELECT * FROM my_table INTO OUTFILE 'my_table.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n';

Copied From : export mysql list of tables from mysql to csv file using php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.