Welcome Guest, Not a member yet? Register   Sign In
active record - get_where doesnt work properly.
#1

[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?!
#2

[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.
#3

[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');




Theme © iAndrew 2016 - Forum software by © MyBB