Next button giving error when on last page. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Next button giving error when on last page. (/showthread.php?tid=52988) |
Next button giving error when on last page. - El Forum - 07-05-2012 [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 To clarify, this does not happen on any of the other image links. The IF statement Code: $nextimg = $data['img']->id + 1; The database call from the model Code: function get_next_image_by_id($id) { 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) Next button giving error when on last page. - El Forum - 07-05-2012 [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 Then, in your view, just check if $next is false, and if it isn't, display the link/image. Next button giving error when on last page. - El Forum - 07-05-2012 [eluser]jim-_-[/eluser] Nice, worked like a charm. Now I see how I have to write a lot of code differently. Thank you very much Next button giving error when on last page. - El Forum - 07-05-2012 [eluser]Aken[/eluser] Wasn't good enough for me. Here's even better: Code: // MODEL Next button giving error when on last page. - El Forum - 07-05-2012 [eluser]jim-_-[/eluser] Now I'm confused, you split it into two different functions for the model ? The get_image_by_id, does this override the model-function I am fetching the image with or is it an additional function? (the single image page, gets the Image and the next image...) Next button giving error when on last page. - El Forum - 07-05-2012 [eluser]Aken[/eluser] The get_image_by_id() method probably does something very similar to the method you're using to fetch the image. It depends on how your model is laid out and what information you're retrieving. |