Forum Moderators: coopster
I could really use your help. I am contructing a small photo gallery that the client can manage. (if you want to see the real thing in action, visit my profile)
1. He uploads his photos into a basic form and chooses the category.
2. When the user chooses a particular category page, the script pulls the thumbnails out of the MySQL database and displays them, five to a page.
3. After five are pulled from the db, the script adds a "next" link to view the next five. (And a "prev" link):
<?PHP
// rows to return
$limit=5;
$thumbnail = $row['thumbnail'];
$title = $row['title'];
$query = "select * from photo_gallery where category_id = 3
order by photo_id desc";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
// next determine if s has been passed to script, if not use 0
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 " <a href='http://www.example.com$PHP_SELF?photo_id=$rows[photo_id]'>";
echo "<img src='http://www.example.com/galleryscript/_files/photogallery/$thumbnail' width=75 height=50 border=1>";
echo "</a>";
echo " ";
$count++ ;
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br />";
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
Prev</a>  ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next >></a>";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
?>
4. Now, when a user select the page of thumbnails, the script checks to see if a thumbnail has already been clicked. If not, it displays a basic starter photo. Otherwise, the script displays the enlarged version of the thumbnail, when the thumbnail is clicked:
<?php
$yes = $_GET['photo_id'];
$photo = $row['photo'];
if (isset($yes)) {
$query = "SELECT * FROM photo_gallery WHERE photo_id = ".$_GET["photo_id"];
$results=mysql_query($query) or die (mysql_error());
while ($rows=mysql_fetch_array($results)) {
extract ($rows);
echo "<img src='http://www.example.com/galleryscript/_files/photogallery/$photo' width=400 height=300 border=1>";
echo "<br>";
echo "$title";
}} else {
echo "<img src='images/2.jpg' width=400 height=300 border=1>";
}
?>
The problem is, that if a user clicks the "next" link in the thumbnail display, and, say, pages back to the 3rd page of 5 thumbs, THEN clicks a thumbnail, the display of thumbs reverts back to page 1. I would like for the thumbs to remain on the 3rd, 2nd page, whichever the user is on.
I've tried a number of fixes, but so far, nothing is working. This form is posting to itself. Hopefully, that's not a problem that is insurmountable.
Any suggestions, fixes or help would be GREATly appreciated.
Best Regards,
Pat
echo " <a href='http://www.example.com$PHP_SELF?photo_id=$rows[photo_id]'>"; You're missing a semi-colon in the entity reference:
and a slash in the URI: ...example.com/$PHP_SELF... [edited by: StupidScript at 5:14 pm (utc) on May 22, 2007]
Also, an unsolicited suggestion, where you're doing:
$yes = $_GET['photo_id'];
$photo = $row['photo'];
if (isset($yes)) {
if $_GET['photo_id'] isn't set you'd generate a warning (which your errorlevel may be suppressing). It would be better to
if(isset($_GET['photo_id']))
$yes = $_GET['photo_id'];
else
...
Add your current page to your image link:
echo " <a href='http://www.example.com$PHP_SELF?photo_id={$rows['photo_id']}&s=$s'>";
(or something similar) - I'm not seeing where $s is first calculated; you need to ensure that when you get to this line, the value of $s is the current page. Also note the addition of the braces around the variable name.
SCORE!
That worked. THANK you!
I will get to work on the if/then suggestion as well.
Many thanks! ALWAYS appreciated!
Pat