This script is a modification of one I use in a photo display system which includes thumbnails in the database. See
http://www.herbhost.com/seasia/
to see the full photo display system. Select a main category, then click on a pic to see this script in action.
Let me know if you want the whole script.
The script below was derived from the one I use to display my photos and it works against the MySql database I have.
The calling URL is
http://www.yourdomain.xxx/photoview.php?thumb=xxx
where xxx is the key into your database (must be numeric)
photoview.php
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>Your Page Title Goes Here</title>
</head>
<?php
// this script displays a picture when it is supplied with a key
// into the database (thumbid). it permits seqential movement
// through the photos. it also displays the annotation or
// caption associated with the photo.
// clean up input
$thumb = substr($thumb, 0, 4);
$thumb = EscapeShellCmd($thumb);
// build query for a thumbnail
$query = "SELECT filename, annotation FROM thumbs
WHERE thumbid >= $thumb
LIMIT 1";
// connect to the database
if(!($dbh=mysql_connect ("localhost",
"YOUR_DATABASE_HERE",
"YOUR_PASS_HERE")))
die("Cannot connect to the database");
// open the connected database
if (!mysql_select_db("YOUR_DATABASE_HERE",$dbh))
die("Cannot open the database");
// get the requested thumb
if (!($result = @ mysql_query ($query, $dbh)))
die("Cannot execute query against the database");
?>
<body link=saddlebrown vlink=black alink=gray>
<font face="Arial"><font size="2"></font></font>
<center>
<?php
// put out the requested image plus some links for next actions
if ($row = @ mysql_fetch_array($result))
{
$filename = $row["filename"];
echo "<img SRC=\"$filename\"><br>";
}
echo "$filename<br>";
$anno = $row["annotation"];
echo "</center><p>$anno</p><center><table BORDER=0 WIDTH=\"100%\">";
$lastthumb = $thumb - 1;
$nextthumb = $thumb + 1;
echo "<tr>";
echo "<td WIDTH=\"50%\" valign=\"top\"><h4><a href=\"photoview.php?thumb=$lastthumb\">";
echo "View Previous Photograph</a></h4></td>";
echo "<td WIDTH=\"50%\" valign=\"top\"><h4><a href=\"photoview.php?thumb=$nextthumb\">";
echo "View Next Photograph</a></h4></td>";
?>
</tr>
</body>
</html>