Welcome Guest, Not a member yet? Register   Sign In
is there any super easy cool trick to get the next id in codeigniter :))
#12

[eluser]NateL[/eluser]
[quote author="David Johansson" date="1248611542"]
But you really need to use an ORDER BY statement!

In active record it would be:
Code:
$query = $this->db->select('id')->order_by('id', 'asc')->get_where('clients', array('id >' => $id), 1, 0);
if($query->num_rows == 1)
{
    $next_id = $query->row()->id;
}
else
{
    $next_id = FALSE;
}
[/quote]

Thanks for cleaning it up and putting it into CI Active Record for me Smile

Now, I'm not doubting you - just curious why you need to use ORDER BY ?

When you say "select by id greater than 5 limit 1" - it's pretty obvious to me it's going to look for the next highest id above 5, so why sort one result?


Messages In This Thread
is there any super easy cool trick to get the next id in codeigniter :)) - by El Forum - 07-26-2009, 10:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB