CodeIgniter Forums
SQL SELECT CASE in codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: SQL SELECT CASE in codeigniter (/thread-40585.html)



SQL SELECT CASE in codeigniter - El Forum - 04-13-2011

[eluser]Unknown[/eluser]
I have the below query but I need to only select field_id_3 and field_id_4 if channel_id is 2, otherwise select field_id_9 and field_id_10

I've just started out doing sql queries with codeigniter so not sure how you would do a CASE SELECT with it.

Code:
<?php
        $this->EE->db->select('entry_id, channel_id, field_id_3, field_id_4, field_id_9, field_id_10', FALSE);
        $this->EE->db->from('exp_channel_data AS cd');
        $this->EE->db->where('entry_id', '{entry_id}');
        
        $query = $this->EE->db->get();
    ?>