Reputation: 299
Probably quite a simple one, but I'm not having any luck in the docs or searches.
I'm trying to add an order by clause to just one of my ActiveRecord queries as follows:
$result = $this->db->get('mytable');
$this->db->order_by('age', 'ASC');
It works, however I get errors because the order by clause is being applied to all my other queries and I get errors because my age column is not present in all tables.
So how do it limit $this->db->order_by('age', 'ASC') to just that one specific query?
Thanks.
Upvotes: 3
Views: 10422
Reputation: 1285
It should be in this format
$this->db->where("tablename.column", $task_id);
$this->db->order_by('tablename.column', 'ASC'); // or 'DESC'
$this->db->from('table');
Upvotes: 4
Reputation: 818
You should have $this->db->order_by();
before $result = $this->db->get('mytable');
Upvotes: 5