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

[eluser]jim-_-[/eluser]
I'm learning so I'm making a page for Images, where i upload images and input info to the Database, the urls are made to look like direct image links, The 3rd segment is the filename I just redirect the <img src=""> tag to the right directory then do a DB call to get the image.

I collect the ID also + 1 and make another DB call to get a thumbnail for the Next button, I have made a IF query to check if the DB call returns anything, if it doesn't I send the user to the first image instead...

here is the problem when I'm on this last page it still gives me the

Code:
Severity: Notice
Message: Undefined offset: 0
Filename: models/gallery_model.php
Line Number: 112

To clarify, this does not happen on any of the other image links.

The IF statement
Code:
$nextimg = $data['img']->id + 1;
   if ($this->gallery_model->get_next_image_by_id($nextimg))
        { $data['next'] = $this->gallery_model->get_next_image_by_id($nextimg); }
   else { $data['next'] = $this->gallery_model->get_next_image_by_id('1'); }

The database call from the model
Code:
function get_next_image_by_id($id) {
$this->db->where('id', $id);
$query = $this->db->get('img');
$image = $query->result();
return $image[0];
}

PS: I'm not 100% in any of the languages I'm only able to learn by doing.

Second question,
I know $image[0] gets the first image from the query, there should only be one image, why is it an array (I know its my coding that makes it an array I just need to know how I can do it different.) on the other hand this saves the site from crashing if I have a duplicate answer to the query. (This ID field is not Auto Increment, I will only give sequential IDs to "approved" images)


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