Forum Moderators: coopster

Message Too Old, No Replies

Image gallery - PHP coding question

         

mcjohnson

11:42 am on May 13, 2007 (gmt 0)

10+ Year Member



I've put together a simple script to pull tumbnails from a MySql database, display them, then display the larger photo when the thumbnail is clicked.

The script shows 5 thumbs per page. When you click "next" you get the next 5 thumbs.

The problem is this: If you click to a second or 3rd page of thumbnails, and then click one of the thumbs to enlarge, the page goes back to page ONE of the thumbs. I would like the page to remain on the 2nd or 3rd page of thumbs, whereever the user happens to be.

Is it possible to look at this script to determine where the issue is and what code I can tweak to make it post to itself and remain where it is without reverting to the page one of thumbnails?

Thanks very much.

<?PHP
// rows to return
$limit=5;
$date = date("Y-m-d");
$title =$row['title'];
$summary =$row['summary'];
$news_id = $row['news_id'];
$thumbnail = $row['thumbnail'];
$title = $row['title'];

$query = "select * from photo_gallery where category_id = 1
order by photo_id desc";

$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);

if (empty($s)) {
$s=0;
}

$query .= " limit $s,$limit";
$count = 1 + $s ;
$results=mysql_query($query) or die (mysql_error());
while ($rows=mysql_fetch_array($results)) {
extract ($rows);
echo "&nbsp<a href='http://www.example.com/new/architecturalgallery.php?photo_id=$rows[photo_id]'>";
echo "<img src='http://www.example.com/oneadmin/_files/photogallery/$thumbnail' width=75 height=50 border=1>";
echo "</a>";
echo "&nbsp;";

$count++ ;
}

$currPage = (($s/$limit) + 1);

//break before paging
echo "<br />";

if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt;
Prev 5</a>&nbsp&nbsp;";
}

$pages=intval($numrows/$limit);

if ($numrows%$limit) {

$pages++;
}

if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

$news=$s+$limit;

echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 5 &gt;&gt;</a>";
}

$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
?>

[edited by: eelixduppy at 2:38 pm (utc) on May 13, 2007]
[edit reason] use example.com for exemplification, thanks [/edit]

Nutter

4:00 pm on May 13, 2007 (gmt 0)

10+ Year Member



I didn't look at your code, but I've got something similar going on a project of mine. What you'll need to do is to know where in the list of files the current full sized image is to know what page to send the visitor back to when they click the link to go back to the thumbnails.

Say you have 15 images at 5 per page and the visitor is on image 12. You'll need to know that image 12 shows up on thumbnail page 3. Off the top of my head the math is ceil($current_position / $total_images) so image 12 would be ceil(12/15) which is 3.

Edit...

Thought of another idea. You could also pass the page number as a variable from the thumbnail page to the fullsized and then just use that variable. Something like /index.php?p=fullsize&page=3.

[edited by: Nutter at 4:01 pm (utc) on May 13, 2007]

mcjohnson

1:28 am on May 15, 2007 (gmt 0)

10+ Year Member



The problem is that the thumbnails are produced dynamically. They'll be ever changing, and thus I can't point to a specific page in a URL as there really is only one PHP page that's delivering the info from the db. The issue is that I just need the current set of thumbnails to remain in place when the user clicks to enlarge.

Any takers?