OK... The following scripts display a table of thumbnails, then display a single photo when a thumbnail is clicked. I know they work since they drive this website.
http://www.herbhost.com/seasia/index.htm
thumbview.php produces the table of thumbnails.
getthumb.php retrieves the thumbnail image from the database for display on the thumnail page
viewphoto.php displays a photo when the link is clicked. The full size photos are NOT stored in the database.
Of miscellaneous note: I've got background images, etc. in this script. You will need to edit to work on your system.
I've had to split this script into two parts to get under the 10,000 character limit on this system. Here is the first half.
thumbview.php - display thumbnails
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<?php
// this script displays thumbnail images from a mysql database which
// is essentially a copy of a ThumbsPlus Access database. A second
// table (pagedata) is used for heading descriptions for each folder
// id this page for future reference
$foldermax = 15; // largest folder number of photos
// $folderid is the primary selection key - hanoi, saigon, etc.
// $pageid is the page number to print for mult pages in a folder
// clean up input
$pageid = substr($pageid, 0, 2);
$pageid = EscapeShellCmd($pageid);
$folderid = substr($folderid, 0, 2);
$folderid = EscapeShellCmd($folderid);
// build query to get folder data
if ($folderid == 1)
{
$skipfolders = 0;
$foldercount = 2;
}
else if ($folderid == $foldermax)
{
$skipfolders = $folderid - 2;
$foldercount = 2;
}
else
{
$skipfolders = $folderid - 2;
$foldercount = 3;
}
$folderquery = "SELECT * FROM pagedata
LIMIT $skipfolders, $foldercount";
// build query for list of thumbnails up to 37 max
$skiprows = (($pageid - 1) * 28); // number of thumbs to skip in query
$query = "SELECT thumbid, annotation, filename FROM thumbs
WHERE pageno = $folderid
ORDER BY filename
LIMIT $skiprows, 37";
// connect to the database
if(!($dbh=mysql_connect ("localhost",
"$username",
"$pass")))
die("Cannot connect to the database");
// open the connected database
if (!mysql_select_db("$database",$dbh))
die("Cannot open the database");
// get the folder information for page descriptions and save what we need
// for prior, current, and next folder
if (!($folderresult = @ mysql_query ($folderquery, $dbh)))
die("Cannot execute query against the database - pagedata");
// 1st record is old data for all but first folder
$folderrow = @ mysql_fetch_array($folderresult);
if ($folderid == 1)
{
$titlestr = $folderrow["title"];
$imagefile1 = $folderrow["image1"];
$imagefile2 = $folderrow["image2"];
$imagefile3 = $folderrow["image3"];
$pagetext = $folderrow["pagetext"];
$pagedesc = $folderrow["description"];
}
else
{
$olddesc = $folderrow["description"];
}
// 2nd record is current data for all but first folder
$folderrow = @ mysql_fetch_array($folderresult);
if ($folderid == 1)
{
$nextdesc = $folderrow["description"];
}
else
{
$titlestr = $folderrow["title"];
$imagefile1 = $folderrow["image1"];
$imagefile2 = $folderrow["image2"];
$imagefile3 = $folderrow["image3"];
$pagetext = $folderrow["pagetext"];
$pagedesc = $folderrow["description"];
}
// third record exists for all but first and is next folder data
if ($folderrow = @ mysql_fetch_array($folderresult))
$nextdesc = $folderrow["description"];
// return the rows for this page - if the rows are less than 37 we
// either have only one page or the last page of a query. if 37 or
// greater we know we have at least 3 rows for a second page, using
// 28 rows per page... doing this way stops single row orphan pages
if (!($result = @ mysql_query ($query, $dbh)))
die("Cannot execute query against the database - thumbs");
// if we got some rows back then get some numbers and output page
$numrows = mysql_num_rows($result);
if ($numrows > 0)
{
if ($numrows < 37) // put all thumbs on this page
{
$tablerows = floor($numrows / 4);
if (($numrows % 4) > 0)
$tablerows = $tablerows + 1;
$newpageid = $pageid;
}
else // more pages to come - 28 per page
{
$tablerows = 7;
$newpageid = $pageid + 1;
}
echo "<title>$titlestr</title>"; // put out the title
?>
</head>
<body background="Paper08.jpg" link=saddlebrown vlink=black alink=gray>
<font face="Arial"><font size="2"></font></font>
<center>
<?php
// put out the images that make the header
if ($imagefile1 != "X")
echo "<img SRC=\"$imagefile1\"><br>";
if ($imagefile2 != "X")
echo "<img SRC=\"$imagefile2\"><br>";
if ($imagefile3 != "X")
echo "<img SRC=\"$imagefile3\"><br>";
// put out the folder descriptive text on first page only
if ($pageid == 1)
echo "</center><br><p>$pagetext</p><center>";
// put out the page description and page number unless only
// one page, then just page description
echo "<h3>";
if (($pageid == 1) and ($newpageid == $pageid))
{
echo"$pagedesc Photos Below";
}
else
{
echo "$pagedesc Photos - Page $pageid Below";
}
echo "</h3>";
// put out some top of page links to other pages
?>
<h5>Click on Any Photo for the Larger Version</h5>
<table BORDER="0" WIDTH="100%">
<tr>
<?php
// if not in the first folder, make link back to previous
$colcnt = 0;
if ($folderid > 1)
{
$colcnt += 1;
$oldfolderid = $folderid - 1;
echo "<td WIDTH=\"25%\"><h4><a href=\"thumbview.php?folderid=$oldfolderid&pageid=1\">";
echo "Back to the $olddesc Photos</a></h4></td>";
}
// if not on the first page, make link to previous page
if ($pageid > 1)
{
$colcnt += 1;
$oldpageid = $pageid - 1;
echo "<td WIDTH=\"25%\"><h4><a href=\"thumbview.php?folderid=$folderid&pageid=$oldpageid\">";
echo "$pagedesc Photos - Page $oldpageid</a></h4></td>";
}
// if not the last page, make link to next page in folder
if ($newpageid != $pageid) // more than one page
{
$colcnt += 1;
echo "<td WIDTH=\"25%\"><h4><a href=\"thumbview.php?folderid=$folderid&pageid=$newpageid\">";
echo "$pagedesc Photos - Page $newpageid</a></h4></td>";
}
// now if it is not the last folder make a link to the next folder
if ($folderid < $foldermax)
{
$colcnt += 1;
$newfolderid = $folderid + 1;
echo "<td WIDTH=\"25%\"><h4><a href=\"thumbview.php?folderid=$newfolderid&pageid=1\">";
echo "Go to the $nextdesc Photos</a></h4></td>";
}
while ($colcnt < 4)
{
echo "<td WIDTH=\"25%\"><br></td>";
$colcnt += 1;
}
?>
The remainder of the code is in the next post... the guts of the thumbnail display.