Welcome Guest, Not a member yet? Register   Sign In
Next button giving error when on last page.
#2

[eluser]Aken[/eluser]
When you're performing the query, you're looking for an image that doesn't exist. So there are no results. $image[0] doesn't exist because $image is an empty array ($query->result() will always return an array).

Here's how I would do it:

Code:
// MODEL

function get_next_image($current_id)
{
$next_id = $current_id + 1;

$query = $this->db->where('id', $next_id)->get('img');

if ($query->num_rows() === 1)
{
  // Next image found.
  $result = $query->result();
  return $result[0];
}
else
{
  // No image found - go back to the first.
  $f_query = $this->db->where('id', 1)->get('img');
  
  if ($f_query->num_rows() === 1)
  {
   $f_result = $f_query->result();
   return $f_result[0];
  }
  
  // No first image found.
  return FALSE;
}

// In case everything above breaks.
return FALSE;
}

// CONTROLLER

$data['next'] = $this->gallery_model->get_next_image($data['img']->id);

Then, in your view, just check if $next is false, and if it isn't, display the link/image.


Messages In This Thread
Next button giving error when on last page. - by El Forum - 07-05-2012, 10:00 AM
Next button giving error when on last page. - by El Forum - 07-05-2012, 11:51 AM
Next button giving error when on last page. - by El Forum - 07-05-2012, 12:13 PM
Next button giving error when on last page. - by El Forum - 07-05-2012, 12:23 PM
Next button giving error when on last page. - by El Forum - 07-05-2012, 12:36 PM
Next button giving error when on last page. - by El Forum - 07-05-2012, 02:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB