Jump to content

Recommended Posts

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]<?php

include_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
Link to comment
https://forums.phpfreaks.com/topic/19407-image-gallery-fake-pagination/
Share on other sites

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 previous

I'm thinking on the lines of mysql_num_rows
[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' link
if this image.page is number 1 there are no previous so don't show a link, otherwise previous = this page -1

Do we need a 'next' link
if 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
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.