Hey all, I recently put together this photo album from a lesson I read in a PHP Beginner book. It works great, but the book did not cover how to organize the uploaded images into a designated number of columns and rows, as well as the addition of pagination.
Would someone be able to provide me with some direction as to how I add these important features to this piece of code that I have. It would be a great learning experience for me.
<?php
//connect to the database
$link = mysql_connect("localhost", "myName", "Password")
or die("Could not connect: " . msql_error());
mysql_select_db("myName", $link)
or die (mysql_error());
$ImageDir = "images/";
$ImageThumb = $ImageDir . "/thumbs/";
?>
<html>
<head>
<title>Welcome to our Photo Gallery</title>
</head>
<body>
<div align="center">
<center>
<table border="0" cellpadding="2" cellspacing="1" width="80" bgcolor="#000000">
<?php
//If cmd is not hit
if(!isset($cmd))
{
//get the thumbs
$getpic = mysql_query("SELECT * FROM profileimages")
or die(mysql_error());
while ($rows = mysql_fetch_array($getpic)) {
$id=$rows["image_id"];//take out the id
extract($rows);
echo "<tr>\n";
echo "<td bgcolor='#CCCCCC'><p align='center'>\n";
echo "<a href=\"".$ImageDir . $image_id . ".jpg\">\n";
echo "<img src=\"" . $ImageThumb . $image_id . ".jpg\" border=\"0\">";
echo "</a>\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td bgcolor='#EFEFEF'><p align='center'>" . $image_caption . "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td bgcolor='#FFFFFF'><p align='center'>\n";
echo "<a href='phgallery.php?cmd=delete&id=$id'>Delete</a>\n";
echo "</td>\n";
echo "</tr>\n";
}
}
if($cmd=="delete")
{
$sql = "DELETE FROM profileimages WHERE image_id=$id";
$getpic = mysql_query($sql);
echo "Image deleted!<br>";
echo "<a href='phgallery.php'>Return to the Gallery</a>\n";
}
?>
</table>
</center>
</div>
</body>
</html>
I'd like to set it to display the images in 4 column 4 rows.
An example can be found here:
http://www.toofly.com/phgallery.php
I've searched many areas but couldn't find any decent advice that fits this particular project.