I am trying to retrieve the next row in my database using Codeigniter\'s active record.
Model
public function getNextRow()
{
$this-&
next_row() returns:
Next row of result set, or NULL if it doesn’t exist:
so, if there is no next result set, you get the error
"Trying to get property of non-object"
because $nxt
is null and not a result set and therefore you cannot $nxt->id;
you get into this situation, because your result set is limited by your query to 1 row only (therefore no more rows)
anyway you can handle this in your model (removing limits):
public function getNextRow()
{
$query = $this->db->get('portfolio_shots');
return $query->next_row();
}
and in the controller (handle case if last row was reached):
public function test()
{
$nxt = $this->Portfolio_model->getNextRow();
if($nxt){
$nxt->id;
}else{
echo 'EOF';
}
}