/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /** * * Dynamically generates a .csv file by looping through the results of a sql query. * */ function export() { ini_set('max_execution_time', 600); //increase max_execution_time to 10 min if data set is very large //create a file $results = $this->ModelName->query($sql); // This is your sql query to pull that data you need exported //or // The column headings of your .csv file // Each iteration of this while loop will be a row in your .csv file where each field corresponds to the heading of the column foreach($results as $result) { // Array indexes correspond to the field names in your db table(s) $result['ModelName']['id'], $result['ModelName']['received'], $result['ModelName']['status'], $result['ModelName']['content'], $result['ModelName']['name'], $result['ModelName']['email'], $result['ModelName']['source'], $result['ModelName']['created'] ); } } ?>
URL: http://gist.github.com/535882