Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gallery paging

Status
Not open for further replies.

mousematt

MIS
Feb 5, 2001
102
GB
Hi

I've made a site with a couple of gallerys, i've got a page with thumbnails and a basic link to a page that just calls one record from MySQL and then displays the picture from that record, I want to put links to the next and previous pic in that gallery, thing is the table with the pictures records isn't in order of gallery....um i've confused myself now.

Table
id filename gallery
1 pic.jpg 1
2 pic.jpg 2
3 pic.jpg 1

Page for picture
<?php
$result = mysql_query("SELECT * FROM files WHERE f_id = $fid");
if ($row = mysql_fetch_array($result)){
?>
<img src="<?php printf($row["f_file"]); ?>" alt="<?php echo $row["f_name"]; ?>" width="400">
<?php
}
mysql_free_result($result);
?>

If someone knows an easy way to do this i would love to know.

Matt
 
How are the pictures ordered within the gallery? By id?
If so, try:
Code:
<?php
$picnum = $_GET['pic'];
$gallery = $_GET['gallery'];
if (!isset($gallery) || $gallery < 1)
  $gallery = 1;

if (!isset($picnum) || $picnum < 1)
  $picnum = 1;

$rs1 = mysql_result("SELECT COUNT(*) AS len FROM files WHERE 
gallery=$gallery");

$len = mysql_result($rs1, 0, 'len');

if ($picnum > 1)
  echo '<a href="' . PHP_SELF . '?gallery=' . $gallery . '&pic=' . ($picnum-1) . '">Back</a>';
if ($picnum < $len)
  echo '<a href="' . PHP_SELF . '?gallery=' . $gallery . '&pic=' . ($picnum+1) . '">Next</a>';

echo "<br><br>";

$rs2 = mysql_result("SELECT filename FROM files WHERE gallery=$gallery ORDER BY id LIMIT $picnum, 1");
$file = mysql_result($rs2, 0, 'filename');

echo '<img src="' . $file . '">';

?>
Untested.

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
Gave it ago and can sort of see what you were doing, should have explained myself a bit better. The images get uploaded in random orders, one day an image for gallery 1 might get uploaded then one for gallery 4 so that the ids run one after the other but the next record in the table might be for a different gallery.

What I need to do is find out the next and previous records that have the same gallery number as the present one. When I ran it and tested I got the previous record in the table but not for the same gallery.

Hope this makes a bit more sense.

Matt
 
Code:
$rs2 = mysql_result("SELECT filename FROM files WHERE gallery=$gallery ORDER BY id LIMIT $picnum[red]-1, 3[/red]");
This code does the following:

Selects the filename from the table "files" if the gallery number is the one supplied
Orders them by id
Takes the one in the order before picnum, picnum, and the one after.

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
I have a similar problem which I can't manage to sort.

I have an image gallery which is filtered by $folderRef and then the $picID within the folderRef.

I want to create a next button that simply pulls out the next row in the database and display the image, but for the life of me, can't find a way of doing it. Please help...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top