Jump to content

photo gallery help.


jeppers

Recommended Posts

well i am working on a photo gallery and it works. pulls info and displays it. thumb nails and main image

 

The problem is when i go on to another page and it displays another 4 images.

you click to view these images and instantly  the page changes and goes back to the start of the query showing the first images again. what i want to happen is when the image is clicked i want it to stay on that page.

 

i am not sure what to do can you help. please if you need any more info please get in contact.

 

thanks

<?php
// include MySQL connector function
if (! @include('includes/mysql_conn.php')) {
  echo 'Sorry, page unavailable';
  exit;
  }
// define number of columns in table
define('COLS', 2);
// set maximum number of records per page
define('SHOWMAX', 6);
// create a connection to MySQL
include ('includes/mysql_db.php');
// prepare SQL to get total records
$getTotal = 'SELECT COUNT(*) FROM images';
// submit query and store result as $totalPix
$total = mysql_query($getTotal);
$row = mysql_fetch_row($total);
$totalPix = $row[0];
// set the current page
$curPage = isset($_GET['curPage']) ? $_GET['curPage'] : 0;
// calculate the start row of the subset
$startRow = $curPage * SHOWMAX;
// prepare SQL to retrieve subset of image details
$sql = "SELECT * FROM images LIMIT $startRow,".SHOWMAX;
// submit the query (MySQL original)
$result = mysql_query($sql) or die(mysql_error());
// extract the first record as an array
$row = mysql_fetch_assoc($result);
// get the name for the main image
if (isset($_GET['image'])) {
  $mainImage = $_GET['image'];
  }
else {
  $mainImage = $row['filename'];
  }
// get the dimensions of the main image
$imageSize = getimagesize('images/'.$mainImage);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Salsa In Cumbria
<?php if (isset($title)) {echo "&#8212;{$title}";} ?>
</title>
<link href="includes/journey.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="header">
    <h1>Salsa Nights</h1>
</div>

    <div id="maincontent">
        <h1>Salsa Nights</h1>
	<div id="wrapper">
        <p id="picCount">Displaying <?php echo $startRow+1;
	  if ($startRow+1 < $totalPix) {
	    echo ' to ';
		if ($startRow+SHOWMAX < $totalPix) {
		  echo $startRow+SHOWMAX;
		  }
		else {
		  echo $totalPix;
		  }
		}
	  echo " of $totalPix";
	  ?></p>
        <div id="gallery">
            <table id="thumbs">
                <tr>
                    <!--This row needs to be repeated-->
                    <?php
				// initialize cell counter outside loop
				$pos = 0;
	            do {
				  // set caption if thumbnail is same as main image
	              if ($row['filename'] == $mainImage) {
	                $caption = $row['caption'];
		            }
	             ?>
                    <td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?image=<?php echo $row['filename']; ?>"><img src="images/thumbs/<?php echo $row['filename']; ?>" alt="<?php echo $row['caption']; ?>" width="80" height="54" /></a></td>
                    <?php
	  			$row = mysql_fetch_assoc($result);
				// increment counter after next row extracted
	 			$pos++;
	  			// if at end of row and records remain, insert tags
				if ($pos%COLS === 0 && is_array($row)) {
	    		  echo '</tr><tr>';
				  }
	  			} while($row);  // end of loop
	  			// new loop to fill in final row
				while ($pos%COLS) {
	    		  echo '<td> </td>';
				  $pos++;
			      }
	 			 ?>
                </tr>
                <!-- Navigation link needs to go here -->
                <tr>
                    <td><?php
			    // create a back link if current page greater than 0
			    if ($curPage > 0) {
				  echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'">< Prev</a>';
				  }
			    // otherwise leave the cell empty
			    else {
				  echo ' ';
				  }
			    ?>
                    </td>
                    <?php
			    // pad the final row with empty cells if more than 2 columns
			    if (COLS-2 > 0) {
				  for ($i = 0; $i < COLS-2; $i++) {
				    echo '<td> </td>';
				    }
				  }
			    ?>
                    <td>
				<?php
			    // create a forwards link if more records exist
			    if ($startRow+SHOWMAX < $totalPix) {
				  echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'">Next ></a>';
				  }
			    // otherwise leave the cell empty
			    else {
				  echo ' ';
				  }
			    ?>
                    </td>
                </tr>
            </table>
            <div id="main_image">
                <p><img src="images/<?php echo $mainImage; ?>" alt="<?php echo $caption; ?>" <?php echo $imageSize[3]; ?> /></p>
                <p><?php echo $caption; ?></p>
            </div>
        </div>
    </div>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/186783-photo-gallery-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.