Welcome Guest, Not a member yet? Register   Sign In
Exporting current query results to CSV
#1

[eluser]eokorie[/eluser]
Hi,

Is there a way I can export current query results to CSV? I have look through the forums and in most examples, you either have to export the entire table. In my current scenario, I have filtered my data to display a particular set of results and its the filtered output that I want to export as CSV.

Anyone have an idea on achieving this?

Thanks

eokorie
#2

[eluser]NeoArc[/eluser]
Try

$this->load->dbutil();

$query = $this->db->query("SELECT * FROM mytable");

echo $this->dbutil->csv_from_result($query);

http://ellislab.com/codeigniter/user-gui...ities.html
#3

[eluser]eokorie[/eluser]
Hi NeoArc,

That just allows you to export the entire contents of a table to a csv. However the data is not filtered! Thanks again however.
#4

[eluser]NeoArc[/eluser]
You should learn some MySQL Wink

$query = $this->db->query(“SELECT id, name, date, telephone FROM users
WHERE creation_date < '2010-11-10' AND status=1 ORDER BY id DESC LIMIT 20”);




Theme © iAndrew 2016 - Forum software by © MyBB