Forum Moderators: coopster
I am trying to create a simple image gallery. I have an index page in html that displays 5 pics. The problem I am having is creating the dynamic php page. I want it so that when I click on one of the images, the php page will display the image I clicked on with the description of that image.
The image address and description are stored in a database. Shown below is the code I have done so far:
For the html page:
<form method="post" action="template.php">
<div class="img">
<input type="image" src="Pictures/fireworks.jpg" width="200px" height="180px" alt="Submit Form" id="1">
<div class="desc">Fireworks display</div> </div>
<div class="img">
<input type="image" //image src and height+width id="2">
//another image</div>
</form>.
For the php:
<?php
$id = $_POST['id'];
mysql_connect("localhost", "username", "password") or die('Error: ' . mysql_error());
$db = "db_name";
mysql_select_db($db);
$query1 = "select address from images where imageid = '".$id."'";
$address = mysql_query($query1) or die ('Error retrieving address data');
$query2 = "select name from images where imageid = '".$id."'";
$description = mysql_query($query2) or die ('Error retrieving description data');
?>
<html>
<body>
<div class="img">
<img src="<?php "$address"?>" width="200px" height="180px">
<div class="desc">Description: <?php echo("$description");?> </div>
</div>
</body>
</html>
The table in mysql is images and three fields: imageid, address and description.
Help would be much appreciated.
<inside your first page>
<a href="template.php?id=1"><img src="image1thumb.jpg"></a>
<a href="template.php?id=2"><img src="image2thumb.jpg"></a>
<a href="template.php?id=3"><img src="image3thumb.jpg"></a>
...
<inside template.php>
$id = $_GET['id'];
$result = mysql_query("SELECT address, description FROM images WHERE imageid=$id");
while($row = mysql_fetch_assoc($result)){
$address = $row['address'];
$description = $row['description'];echo "<img src=\"$address\">";
echo $description;
}