AdRock Posted September 1, 2006 Share Posted September 1, 2006 Ihave a small simple image gallery where a user can select a thumbnail from the list and it enlarges on another page.How would I create fake pagination where the user can click links to move forward and back through the images but more importantly not move past the first or last image?Here is the code for what i got so far[code]<?phpinclude_once("includes/connection.php");$id = $_GET['id'];$query = "SELECT * FROM images WHERE id = '$id'"; $result = mysql_query($query) or die(mysql_error());while ($row = mysql_fetch_array($result)) { echo "<img src='/gallery/".$row['image']."'>";}?[/code]I think i can do the moving through the images but not the error trapping at either end of the database Quote Link to comment https://forums.phpfreaks.com/topic/19407-image-gallery-fake-pagination/ Share on other sites More sharing options...
trq Posted September 1, 2006 Share Posted September 1, 2006 In what way would this be [i]fake[/i] pagination. It [b]is[/b] pagination. A search of the board should get you quite a few examples. Quote Link to comment https://forums.phpfreaks.com/topic/19407-image-gallery-fake-pagination/#findComment-84248 Share on other sites More sharing options...
AdRock Posted September 1, 2006 Author Share Posted September 1, 2006 what i thought about was getting the id from the url and either adding one or subtracting one so if i click next it requeries the database and gives the next image. But what i don't know how to do is when it gets to the last record not try and go any further. So when the last record is reached the link that says next disappears....the same as previousI'm thinking on the lines of mysql_num_rows Quote Link to comment https://forums.phpfreaks.com/topic/19407-image-gallery-fake-pagination/#findComment-84277 Share on other sites More sharing options...
AndyB Posted September 1, 2006 Share Posted September 1, 2006 [quote author=AdRock link=topic=106546.msg426210#msg426210 date=1157145783]I'm thinking on the lines of mysql_num_rows[/quote]Then you're on the right track. The logic is very simple:Do we need a 'previous' linkif this image.page is number 1 there are no previous so don't show a link, otherwise previous = this page -1Do we need a 'next' linkif this image/page is the same number as the number of images/pages I have then don't show a link, otherwise next = this page+1 Quote Link to comment https://forums.phpfreaks.com/topic/19407-image-gallery-fake-pagination/#findComment-84287 Share on other sites More sharing options...
sasa Posted September 1, 2006 Share Posted September 1, 2006 pagination[code]$query = "SELECT id FROM images"; $result = mysql_query($query) or die(mysql_error());while ($row = mysql_fetch_array($result)) $link[] = $row['id'];$curent = array_search($id, $link);$prev = $curent - 1;$next = $curent + 1;if (array_key_exists($prev)) echo "<a href=\"?id=$link[$prev]\"> PREV </a>";if (array_key_exists($next)) echo "<a href=\"?id=$link[$next]\"> NEXT </a>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19407-image-gallery-fake-pagination/#findComment-84290 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.