CodeIgniter Forums
Modifying query result before export CSV from result - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Modifying query result before export CSV from result (/showthread.php?tid=55350)



Modifying query result before export CSV from result - El Forum - 10-22-2012

[eluser]dsloan[/eluser]
I have a query which produces a result set in which I want to modify some field values before exporting to CSV. Specically, one column value has an integer value which I want to replace with the appropriate "status" value, e.g. 1=ACTIVE, 2=CEASED, 3=SUSPENDED, etc.

I found this thread which was exactly what I was looking for, but no answer! http://ellislab.com/forums/viewthread/77147/

Anyone any ideas? I have tried looping through the array and modifying, but no joy.

foreach($query->result_array() as &$result)


Modifying query result before export CSV from result - El Forum - 10-22-2012

[eluser]CroNiX[/eluser]
You can do that directly in the query. Either use a join (assuming you have those status' defined in a table) or use a CASE statement in the query.


Modifying query result before export CSV from result - El Forum - 10-23-2012

[eluser]dsloan[/eluser]
Thanks. This is just one example of what I need, but there's several fields which need processed, concatenated and logic applied. That might all be possible to do via SQL but is it possible to do it by modifying the query directly?