Jump to content


Photo

Image gallery fake pagination


  • Please log in to reply
4 replies to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 01 September 2006 - 08:18 PM

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

<?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']."'>";
}

?

I think i can do the moving through the images but not the error trapping at either end of the database
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 01 September 2006 - 08:36 PM

In what way would this be fake pagination. It is pagination. A search of the board should get you quite a few examples.

#3 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 01 September 2006 - 09:23 PM

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
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 01 September 2006 - 09:38 PM

I'm thinking on the lines of mysql_num_rows


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
Legend has it that reading the manual never killed anyone.
My site

#5 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 01 September 2006 - 09:42 PM

pagination
$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>";





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users