View Full Version : PHP Paging Problem

07-10-2008, 05:43 AM
Hi All,

Not sure if the title is helpful but couldnt think of any other title to use.

Been having a problem getting this to work and probably gonna be harder to explain but here goes.

I am working on a gallery page that has three thumbnails and one main image. When the page loads the three thumbs display and the main image of thumb no.1 displays. Click on another thumb and its main image will change. Click on the paging, next/prev and thumbs 3 to 6 display and the last seen main image remains. This is how it was suppose to be and works fine. Now my brother, whose site it is, would like the main image to change to the first of the three thumbs when the paging is clicked.

Current Example: Thumbs 1,2,3 and Main Image 1 (until thumb selected)
click next
Thumbs 4,5,6 and Main Image 1 (until thumb selected)

Required Example: Thumbs 1,2,3 and Main Image 1 (until thumb selected)
click next
Thumbs 4,5,6 and Main Image 4 (until thumb selected)

I've been trying for days but cant suss this out and I'm beginning to think that maybe its not possible. Here is my code for the current version. The site is only available on my local environment so cant put it live.

PHP Code:

include("Connections/PbyDTconnection.php"); // database connection
$ImgCatIDurl = $_GET['ImgCatIDurl'];
$ImageID = $_GET['ImageID'];
$rowsPerPage = 3; //how many rows per page
$pageNum = 1; //by default we show first page
if(isset($_GET['page'])) // if $_GET['page'] defined, use it as page number
{ $pageNum = $_GET['page']; }
$offset = ($pageNum - 1) * $rowsPerPage; // counting the offset
$query = sprintf("SELECT * FROM images where ImgCatID='$ImgCatIDurl' LIMIT $offset, $rowsPerPage");
$result = @mysql_query($query);
$images = @mysql_fetch_array($result);// print the random numbers
$query = "SELECT COUNT(ImageID) AS numrows FROM images WHERE ImgCatID='$ImgCatIDurl'"; // how many rows we have in database
$result2 = mysql_query($query) or die();
$images2 = mysql_fetch_array($result2, MYSQL_ASSOC);
$numrows = $images2['numrows'];
$maxPage = ceil($numrows/$rowsPerPage); // how many pages we have when using paging?
$self = $_SERVER['PHP_SELF']; // print the link to access each page
$nav = " $pageNum of $maxPage pages ";
// creating previous and next link plus the link to go straight to the first and last page

if ($pageNum > 1)
$page = $pageNum - 1;
$prev = " <a href=\"$self?ImgCatIDurl=$ImgCatIDurl&ImageID=$ImageID&page=$page\">Previous</a> ";

$first = " <a href=\"$self?ImgCatIDurl=$ImgCatIDurl&ImageID=$ImageID&page=1\">First</a> ";
$prev = '&nbsp;'; // we're on page one, don't print previous link
$first = '&nbsp;'; // nor the first page link

if ($pageNum < $maxPage)
$page = $pageNum + 1;
$next = " <a href=\"$self?ImgCatIDurl=$ImgCatIDurl&ImageID=$ImageID&page=$page\">Next</a> ";

$last = " <a href=\"$self?ImgCatIDurl=$ImgCatIDurl&ImageID=$ImageID&page=$maxPage\">Last</a> ";
$next = '&nbsp;'; // we're on the last page, don't print next link
$last = '&nbsp;'; // nor the last page link
/////////////////////////////////////////// query for main image
$query = sprintf("select * FROM images where ImageID='$ImageID'");
$result_main = @mysql_query($query);
$image_main = @mysql_fetch_array($result_main);


HTML Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<title>Photography By Dan Tucker</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="PbyDT.css">

<!-- The following conditional code allows the embedded styling to be seen only by IE 6 or less. IE 6 doesn't understand min-width, so this proprietary IE code will take care of that. -->

<!--[if lte IE 6]>
<style type="text/css">
#wrapper {
width:expression( documentElement.clientWidth < 720 ? (documentElement.clientWidth == 0 ? (body.clientWidth < 720 ? "720" : "auto") : "720px") : "auto" );
<body class="gallery">
<div id="wrapper">
<div id="header">
<h1><img id="logo" src="Images/logo.gif" alt="Photography By Dan Tucker" width="400" height="110"></h1>
<div id="nav"><!-- has left_dtl_top.gif background and left padding -->
<div><!-- for rgt_cnr.gif background and right padding -->
<div><!-- for top_dtl.gif background -->
<dt id="home"><a href="index.php">Home</a></dt>
<dt id="gallery"><a href="gallery.php">Gallery</a></dt>
<dt id="about"><a href="about.php">About</a></dt>
<dt id="shop"><a href="shop.php">Shop</a></dt>
<dt id="links"><a href="links.php">Links</a></dt>
<dt id="contact"><a href="contact.php">Contact</a></dt>
</div><!-- end of #nav -->
<div id="content">
<div id="title"><h2><img src="Images/Titles/<?php echo $images['ImgCatImg'] ?>" alt="<?php echo $images['ImgTitle'] ?>" width="400" height="32"></h2>
<div id="gal_holder">
<div id="left_thumbs">
<?php do { ?>
<div class="img_left2">
<div class="img1"><a href="gallery2.php?ImgCatIDurl=<?php echo $images['ImgCatID'] ?>&ImageID=<?php echo $images['ImageID'] ?>&page=<?php echo $pageNum ?>"><img src="Images/Gallery/Thumbs/<?php echo $images['ImgURLthumb'] ?>" alt="<?php echo $images['ImgTitle']?>" title="<?php echo $images['ImgTitle']?>" ></a></div>
<?php }while ($images = mysql_fetch_array($result)) ?>
<div class="img_right2"><p><span class="blue_bold">Description:</span> <?php echo $image_main['ImgTitle'] ?></p>
<div class="img2big"><img src="Images/Gallery/<?php echo $image_main['ImgURLmain'] ?>" alt="<?php echo $image_main['ImgTitle']?>" title="<?php echo $image_main['ImgTitle']?>" ></div>
<div class="paging"><p><span class="blue_bold3"><?php echo $prev ?></span><span class="blue_bold3">|</span><span class="blue_bold3"><?php echo $next ?></span><span class="blue_bold2">Add to Basket</span></p></div>
<div id="footer"><p>&copy; Copyright 2007 &minus; <?php echo date("Y") ?> Photography by Dan Tucker</p></div>
<img id="logo_left" src="Images/logo_left.gif" alt="Photography By Dan Tucker" width="147" height="297">

Hope you can understand this and many thanks.

Regards, Paul

07-10-2008, 05:58 AM

dont understand

you need to message me where we have to chat about it

i cant see this in my mind through text

07-10-2008, 06:02 AM
I thought so Dj, Its a hard one to explain. Off to work now, I'll see if you are online lunchtime if not tonight.

07-10-2008, 06:05 AM
will have to be tonight