Hi Friends
This application creates a simple Photo Gallery in PHP. We have used Arrays in this application. Gallery is displayed in a Tabular format.
We used two types of images-Thumbnails and the original Images.
The Thumbnails are stored in a directory called Thumbs and Original Images are kept in another directory called Images.
We have kept the Thumbnails and the Images in separate arrays. The Description of the images are kept in another array. Check out the code to see How we have used Arrays effectively to create an Image Gallery.
<html>
<head>
<title>Photo Gallery</title>
<style type="text/css">
/*Style for Table*/
table
{
font-family:Arial; font-size:15px;
color:navy; font-weight: normal;
border: 2px solid red;
text-align: center;
border-collapse:collapse; width:30%;
}
th
{
font-family:Arial; font-size:25px;
color:red; font-weight: bold; font-style:italic;
text-align: center; background-color:#FFE4E1
}
</style>
</head>
<body>
<?php
$thumb = array("Thumbs/1.jpg", "Thumbs/2.jpg", "Thumbs/3.jpg", "Thumbs/4.jpg", "Thumbs/5.jpg",
"Thumbs/6.jpg", "Thumbs/7.jpg", "Thumbs/8.jpg" ,"Thumbs/9.jpg", "Thumbs/10.jpg",
"Thumbs/11.jpg", "Thumbs/12.jpg", "Thumbs/13.jpg", "Thumbs/14.jpg", "Thumbs/15.jpg",
"Thumbs/16.jpg", "Thumbs/17.jpg", "Thumbs/18.jpg", "Thumbs/19.jpg", "Thumbs/20.jpg" );
$image = array("Images/1.jpg", "Images/2.jpg", "Images/3.jpg", "Images/4.jpg", "Images/5.jpg",
"Images/6.jpg", "Images/7.jpg", "Images/8.jpg" ,"Images/9.jpg", "Images/10.jpg",
"Images/11.jpg", "Images/12.jpg", "Images/13.jpg", "Images/14.jpg", "Images/15.jpg",
"Images/16.jpg", "Images/17.jpg", "Images/18.jpg", "Images/19.jpg", "Images/20.jpg");
$description = array("Red Hibiscus", "Pink and Yellow Hibiscus", "Marigold", "While Flower", "Red Rose",
"Rose", "Pretty Flower", "White Flower", "Yellow Flower", "Bougainvillea",
"Pink Hibiscus", "Yellow Bougainvillea", "Red Flowers", "Yellow Daffodil", "Pink Flowers",
"Red Flowers", "Small Pink Flowers", "Tulip", "Pink Hibiscus", "Blue Flower");
?>
<table cellpadding = '10' border = '1' align='center'>
<tr>
<th colspan='5'> Flowers Photo Gallery</th>
</tr>
<?php
$a=$b=$k=0;
//j<8 because we want to create 8 rows in this table
for ($j=0;$j<8;$j++){
//creating the row of picture thumbnails
if(($k%2)==0){
echo "<tr bgcolor='pink'> \n";
for ($i=0;$i<5;$i++)
{
echo "<td> \n";
echo "<a href=\"$image[$a]\"><img src=\"$thumb[$a]\" width=\"125\" height=\"125\"></a>";
echo "</td> \n";
$a++;
}
echo "</tr> \n";
}//if end
//Creating Row for Picture Description
else{
echo "<tr bgcolor=''> \n";
for ($i=0;$i<5;$i++)
{
echo "<td> \n";
echo "{$description[$b]}";
echo "</td> \n";
$b++;
}
echo "</tr> \n";
}//else end
$k++;
}//outer for
?>
</table>
<br /> <br /><br />
</body>
</html>
Snapshot of the o/p

Try out this application with your own images.
Happy Programming people.




