Photo Gallery in PHP

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. :D


<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. :D

You know you are a Geek when

You know you are a Geek when

You study on Holidays and Sundays
You feel hurt when you get 9.5/10
Coming 2nd in the class is like a crown of thorns
Parties are a big bore for you.
You can keep on talking about Geeky stuff
You spent most time on Wikipedia
You haven’t seen a movies since ages.
You are always prepared for an exam.
Seeing other ordinary people makes you wonder.
Laptop and Books are your Best Friend and maybe your nerdy group of friends.

Dedicated to all Geeks. :D ;)

Indian States and its Capitals-PHP Application

Hi Friends

This ones an interesting PHP Application where the user needs to select the state name and click on the Submit button. It’s Capital along with a state image will be displayed on another page.

We have used PHP Arrays for this application and kept the images of all the states in a separate directory called stateimages

StatesForm.php

<html>
<head>
<title> Indian States and Capitals</title>

<style type="text/css">
	/*Style for Table*/

	table
	{
	font-family:Arial; font-size:15px;

	color:navy; font-weight: normal;

	border: 1px solid red;

	text-align: center;

	border-collapse:collapse; width:30%;
	}

	h2
	{
	font-family:Arial; font-size:25px;

	color: red; font-weight: bold;

	text-decoration:underline
	}

</style>
</head>

<body>

<h2> Select an Indian State to know its Capital </h2>

<?php
$states= array("Jammu and Kashmir","Punjab","Himachal Pradesh","Rajasthan","Uttar Pradesh","Uttaranchal",
"Gujarat","Madhya Pradesh","Bihar","Jharkand","West Bengal","Assam","Meghalaya","Sikkim","Arunachal Pradesh",
"Manipur","Mizoram","Tripura","Nagaland","Maharashtra","Goa","Chattisgarh","Orissa",
"Andhra Pradesh","Kerala","Tamil Nadu","Lakshwadeep","Pondicherry","Andaman & Nicobar islands",
"Delhi","Dadra and Nagar Haveli","Daman & Diu","Haryana");

sort($states);
?>

<form action="ShowStateCapital.php" method="post">

<table border="0" cellpadding="10">

<tr>
<td> State: </td>
<td>
<?php
echo "<select name='state'>";
echo "<option value='No State'>--Select State--</option>";

	foreach($states as $statevalue)
	{
	  echo "<option value='$statevalue'>$statevalue</option>";
	}

echo "</select>";

?>
</td>
</tr>

 <tr>
 <td colspan="2" align="center"> <br /> <br />
 <input type="submit" value="Submit">
 <input type="reset" value="Reset">
 </td>
 </tr>
</table>

</form>
</body>
</html>

ShowStateCapital.php

<html>
<head>
<title> Indian States and Capitals</title>

<style type="text/css">
	/*Style for Table*/

	h2
	{
	font-family:Arial; font-size:25px;

	color: red; font-weight: bold;

	text-decoration:underline
	}

	h3
	{
	font-family:Arial; font-size:15px;

	color: black;
	}

	span.state {color:blue;font-weight:bold; font-size:15px; font-family:Arial}

	span.capital{color:violet;font-weight:bold; font-size:25px; font-family:Arial}

	img { border:2px solid black}

</style>
</head>

<body>

<h2> Selected State and it's Capital </h2>

<?php

$keystate=$_POST["state"];
$test=0;
echo "<h3>You have selected <span class='state'>$keystate</span></h3>";

$states= array("Jammu and Kashmir"=>"Srinagar","Punjab"=>"Chandigarh","Himachal Pradesh"=>"Shimla","Rajasthan"=>"Jaipur",
"Uttar Pradesh"=>"Lucknow","Uttaranchal"=>"Dehra Dun","Gujarat"=>"Gandhinagar","Madhya Pradesh"=>"Bhopal","Bihar"=>"Patna",
"Jharkand"=>"Ranchi","West Bengal"=>"Kolkata","Assam"=>"Guwahati","Meghalaya"=>"Shillong","Sikkim"=>"Gangtok",
"Arunachal Pradesh"=>"Itanagar","Manipur"=>"Imphal","Mizoram"=>"Aizawl","Tripura"=>"Agartala","Nagaland"=>"Kohima",
"Maharashtra"=>"Mumbai","Goa"=>"Panaji","Chattisgarh"=>"Raipur","Orissa"=>"Bhubaneshwar","Andhra Pradesh"=>"Hyderabad",
"Kerala"=>"Thiruvanthapuram","Tamil Nadu"=>"Chennai","Lakshwadeep"=>"Kavaratti","Pondicherry"=>"Pudducheri",
"Andaman & Nicobar islands"=>"Port Blair","Delhi"=>"New Delhi","Dadra and Nagar Haveli"=>"Silvassa",
"Daman & Diu"=>"Daman","Haryana"=>"Chandigarh");

asort ($states);

foreach($states as $key=>$value)
{
	if($key==$keystate)
    {
		echo "<h3>The capital of <span class='state'>$keystate</span> is
                     <span class='capital'>$value</span></h3>. ";
		echo "<img src=stateimages/$key />";
		$test=1;
		break;
    }
}

if($test==0)
     echo "This state does not exist.";

	echo "<br /> <br /><a href='States.php'>Go Back</a>";
?>

</body>
</html>

Snapshot of the o/p

Try out this application, change it for your country. :D
We all love our country. :D