CodeIgniter Forums
active record - get_where doesnt work properly. - 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 - get_where doesnt work properly. (/showthread.php?tid=55321)



active record - get_where doesnt work properly. - El Forum - 10-20-2012

[eluser]Berzacola[/eluser]
look, today i try to use this active record setting to get the oldest record for a slug in my table:


IT DOESNT WORK, IT GET THE FIRST ID... not the oldest one.
Code:
$query = $this->db->get_where('comments', array('slug' => $slug), 1, 'ORDER BY date ASC');
$pre = $query->result_array();
$id = $pre[0]['id'];

IT WORKS:
Code:
$this->db->select('id');
$this->db->where('slug',$slug);
$this->db->order_by('date','asc');
$query = $this->db->get('comments',1);
$pre = $query->result_array();
$id = $pre[0]['id'];

it is a bug?!


active record - get_where doesnt work properly. - El Forum - 10-20-2012

[eluser]WanWizard[/eluser]
Where do you get the idea that you can pass an "order by" to get_where()? The fourth parameter is the offset.



active record - get_where doesnt work properly. - El Forum - 10-21-2012

[eluser]srpurdy[/eluser]
like WanWizard said.. You just need to put this above the $query in your first example.
Code:
$this->db->order_by('date','asc');