Aloha,
I've been working on a photo gallery which is slowly, painfully coming together, but I seem to have run into a snag.
I'm getting the thumbnails to come up just fine with paginated results.
I also have it designed so that when you click on a thumbnail a pop up page appears with the full sized picture and it is here on the pop up page where I'm at a loss. I'm grabbing the pictures for the pop up with a query which asks for the picture's ID (pid) and the fighter's ID (fid) just like the one at Sherdog.com. I get the picture in the pop up from the thumbnails page no problemo, but I also want the ability to page through the full sized pop up window of pictures according to that particular fighter's ID (fid) using last, next, previous & first getting the picture's ID (pid). Now all would be great with the script I've got so far, BUT (isn't there always a BUT?) the series of pictures aren't always in order one after the other ie: pic1, pic2, pic6, etc. so I get pages with nothing on them but the navigation where the series has a gap.
I'm looking for a way to have my query and subquery in the //GAPS section of my script
loop until it finds the previous or next picture in the series which matches both in PID and FID.
Here's what's taken me what seems like an eternity so far to come up with.
I'm new to this so if the script looks ugly, bare with me...
PHP Code:
<?
# include connect-file
require_once('includes/connect.inc.php');
# include functions-file
require_once('includes/functions.inc.php');
//GET THE NUM PICS
if(isset($_GET['id']))
{
$id = $_GET['id'];
}
if(isset($_GET['pid']))
{
$pid = $_GET['pid'];
}
// GRABBING TOTAL ROWS (SEEMS REDUNDANT THOUGH)
$getnumrows = "SELECT COUNT(pid) as 'norows' from pics WHERE pics.fid = '".$_GET['id']."'";
$therows = mysql_query($getnumrows);
$rows = mysql_fetch_array($therows, MYSQL_ASSOC);
$ttlrows = $rows['norows'];
// GETTING BEGINNING ROW & PICTURE
$query = "SELECT pid as 'pid' from pics WHERE pics.fid = '".$_GET['id']."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['pid'];
// GETTING LAST ROW & PICTURE
$get_max_pid = "SELECT MAX(pid) as 'maxpid' FROM pics WHERE pics.fid = '".$_GET['id']."'";
$max_pid = mysql_query($get_max_pid);
$prow = mysql_fetch_array($max_pid, MYSQL_ASSOC);
$mpid = $prow['maxpid'];
// GAP JUMPING - NOT WORKING
$gapsql = "SELECT pid AS pid, fid AS fid FROM pics WHERE fid = '".$_GET['id']."' AND pid = ";
// PREVIOUS
$sub_query .= $_GET['pid'] - 1;
$pregap = $gapsql . $sub_query;
$gap1 = mysql_query($pregap);
$prerow = mysql_fetch_array($gap1, MYSQL_ASSOC);
$previous = $prerow['pid'];
// NEXT
$sub_query2 .= $_GET['pid'] + 1;
$nextgap = $gapsql . $sub_query2;
$gap2 = mysql_query($nextgap);
$nextrow = mysql_fetch_array($gap2, MYSQL_ASSOC);
$next = $nextrow['pid'];
// END GAP JUMPING -NOT WORKING
// ROOT LINK
$self = $_SERVER['PHP_SELF'];
// START LINKS
if ($pid > $numrows)
{
// $pid = ($_GET['pid'] - 1);
$pid = $previous;
$prev = "<a href=\"$self?id=$id&pid=$pid\"> < </a>";
$first = "<a href=\"$self?id=$id&pid=$numrows\"> FIRST </a>\n";
}
else
{
$prev = " "; // on first page
$first = " "; // on first page
}
if ($pid < $mpid -1)
{
// $pid= ($_GET['pid'] + 1);
$pid = $next;
$next = "<a href=\"$self?id=$id&pid=$pid\"> > </a>\n";
$last = "<a href=\"$self?id=$id&pid=$mpid\"> LAST </a> \n";
}
else
{
$next = " "; // on the last page
$last = " "; //last page
}
// nav links
echo $first . $prev . $next . $last;
// SHOW BIG PIC
$query = "SELECT pics.pid AS 'pid', pics.fid AS 'fid', pics.url AS 'url', pics.thumb AS 'thumb', concat(stats.fname, ' ', stats.lname) AS 'name', stats.fid AS 'fid' FROM pics, stats WHERE pics.fid=stats.fid and stats.fid = '".$_GET['id']."' AND pics.pid = '".$_GET['pid']."' LIMIT 0, 1";
$results = mysql_query($query);
$picsurl = "images/fighter_pics/";
while ($row = mysql_fetch_array($results))
{
list($width, $height, $type, $attr) = getimagesize("$picsurl".$row["url"]."");
echo "<img src=\"$picsurl".$row["url"]."\" height=\"$height\" width=\"$width\" alt=\"".$row["name"]."\" class=\"galpic\" /><br />\n";
}
?>
Any help would be greatly appreciated.
Thanks