Article
Build An Automated PHP Gallery System In Minutes
Screen 3: The Full-Size Image
The values for the category id via the input variable cid, and the photo id via the input variable pid, are required for this screen to appear (i.e. viewgallery.php?cid=1&pid=2).
In this final step, we need to display at full size the image uploaded. The following code is pretty basic; it looks up the filename in the gallery_photo table on the basis of the image id provided, and then displays it along with its caption.
else if ($pid) {
$result = mysql_query("
SELECT
photo_caption,
photo_filename
FROM gallery_photos
WHERE photo_id = '" . addslashes($pid) . "'
");
list($photo_caption, $photo_filename) = mysql_fetch_array($result);
$nr = mysql_num_rows($result);
mysql_free_result($result);
if (empty($nr)) {
$result_final = "\t<tr><td>No Photo found</td></tr>\n";
} else {
$result = mysql_query("
SELECT category_name
FROM gallery_category
WHERE category_id = '" . addslashes($cid) . "'
");
list($category_name) = mysql_fetch_array($result);
mysql_free_result($result);
$result_final .= "<tr>\n\t<td>
<a href='viewgallery.php'>Categories</a> >
<a href='viewgallery.php?cid=$cid'>$category_name</a></td>\n</tr>\n";
$result_final .= "<tr>\n\t<td align='center'>
<br />
<img src='$images_dir/$photo_filename' border='0'
alt='$photo_caption' />
<br />
$photo_caption
</td></tr>";
}
}
Our output will look something like this:

After putting it all together, you should print the value in $result_final using appropriate html tags, and save the file as viewgallery.php. Again, this file is part of the archive you can download here.
Create Direct Links to Categories and Images
To create direct links from other pages of our site to the categories, we just need to know the Category Id. For example, to link to Category Id = 1 you can use the following URL:
http://www.yoursite.com/gallery/viewgallery.php?cid=1
To link up an image, you need to know its Photo Id and as well as its Category Id:
http://www.yoursite.com/gallery/viewgallery.php?cid=1&pid=1
The above link will open the Photo Id = 1 if that exists in the Category Id 1.
Creating Sub-Categories
Some of us may like to have sub-categories within our categories, which would provide much more depth to our gallery system. To allow for subcategories, we’d add another field to our category table, to hold the ID of the parent category. This ID would then have to be employed in devising the category listing code, to produce a sub-category list.
A separate section would be required to be to handle the display of any sub-categories within a parent category.