Active Record question - 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: Active Record question (/showthread.php?tid=48802) |
Active Record question - El Forum - 01-29-2012 [eluser]Bondie[/eluser] Is there anyway of producing a query with active record to order by id, not by asc or desc, but to provide an order for example; 5,7,3? SQL would be something along the lines of... Code: SELECT Edit here's my attempt: Code: $comma_separated = implode(",", $this->_get_recently_viewed()); Here's my error: Quote:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6the final ` the offending object? Active Record question - El Forum - 01-29-2012 [eluser]vbsaltydog[/eluser] Can you order that way in SQL without active record? Active Record question - El Forum - 01-29-2012 [eluser]Bondie[/eluser] Code: $get_rece = $this->db->query("SELECT `id`, `title`, `slug`, `category_id`, `user_id`, `price`, `date_start`, `date_end`, `description`, `images` FROM (`classifieds_listings`) WHERE `id` IN (".$comma_separated.") AND `date_end` > 1327857702 AND `date_start` < 1327857702 ORDER BY FIELD(`id`, ".$comma_separated.")"); This does the trick, producing: Quote:SELECT `id`, `title`, `slug`, `category_id`, `user_id`, `price`, `date_start`, `date_end`, `description`, `images` FROM (`classifieds_listings`) WHERE `id` IN (3,7,2,6,1) AND `date_end` > 1327857702 AND `date_start` < 1327857702 ORDER BY FIELD(`id`, 3,7,2,6,1) Active Record question - El Forum - 01-29-2012 [eluser]vbsaltydog[/eluser] great signature Active Record question - El Forum - 01-29-2012 [eluser]Bondie[/eluser] Thanks |