Apparently active record cannot deal with temporary tables - huge oversight in my opinion. (ref: Codeigniter 2 active record — How do I create temporary table to apply second sort order? )
In light of this I am looking for a way to sort the result object produced by my query.
Here is my query:
$this->db
->select('*')
->from('item_categories')
->where('item_categories.cat_id', $c)
->or_where('item_categories.parent_id', $c)
->or_where('item_categories.gparent_id', $c)
->join('item_categories_rel', 'item_categories_rel.cat_id = item_categories.cat_id', 'right')
->join('item_entries', 'item_entries.item_id = item_categories_rel.item_id','right')
->join('ratings_total', 'ratings_total.item_id = item_entries.item_id')
->order_by("item_name", "asc")
->limit($l, $s);
$result = $this->db->get();
So for example my results contain a field called site_rating which is of type decimal(2,1) , how can I sort my result object by site_rating in asc/desc order? Any help greatly appreciated.
To be clear I do not want to change the current order, I want to apply a second sort order to the first result set - I have found I cannot do this with active record so would like to do it by sorting the result object if possible.