Currently I created mySQL database with the reference path of images and some additional columns of the database with ID, captions, location etc.
I need to populate a php site with these infomation. An example of the site structure should look like this:
PICTURE (Image with width = 175 height = 200)
Photo taken with Canon Camera (Caption)
Paris (Location)
As you can see, each image should have a caption and location below the picture.
Depending on the mySQL query, all these images retreived from database should be put side by side.
mySQL query is as follows(using php getimage.php):
<?php
$id = $_GET['id'];
$link = mysql_connect("localhost", "root", "");
mysql_select_db("photodb", $link);
$sql = "SELECT photo_path FROM photo WHERE id=$id";
$result = mysql_query($sql, $link);
$row = mysql_fetch_assoc($result);
mysql_close($link);
header("Content-type: image/jpeg");
echo file_get_contents($row['photo_path']);
?>
getcaption.php:
<?php
$id = $_GET['id'];
$link = mysql_connect("localhost", "root", "");
mysql_select_db("photodb", $link);
$sql = "SELECT caption FROM photo WHERE id=$id";
$result = mysql_query($sql, $link);
$row = mysql_fetch_assoc($result);
mysql_close($link);
echo $row['caption'];
?>
I have actually created a css ul with class “grid” for doing this. Currently, my code is as follows:
<ul class="grid">
<li>
<p class="image"><img src="getImage.php?id=1" alt="" width="175" height="200" /></p>
<p class="caption"></p>
<p class="location"></p>
</li>
<li>
<p class="image"><img src="getImage.php?id=2" alt="" width="175" height="200" /></p>
<p class="caption"></p>
<p class="location"></p>
</li>
At the moment, I have two issues.
One – How do i display the caption data in the <p> tag?
Two – As you can see, I have defined only two <li> at the moment. What if my query returns more than two results? What if i did a mySQL insert elsewhere? Should i do a loop somewhere?
Thank you for looking at my issues
1 Answer