Jump to content

Archived

This topic is now archived and is closed to further replies.

AdRock

Image gallery fake pagination

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.