Reputation: 1297
I am building an image uploading website. Images are uploaded to a directory on the server and data such as the filename is stored in a MySql table. I have created a 'gallery' page which displays all the uploaded images as thumbnails. When a user clicks on one of the images, it takes them to 'image.php' page, which will display the image full size and echo information such as the username of the person who uploaded the image etc.
I am unsure as to what would be the correct way of displaying the image. The images in my MySql table have unique ID's which I'm guessing will have to be manipulated in some way, but how do I would I get the ID of the photo that has been clicked on into the 'image.php' MySql query?
Hope this has been explained well enough. Thanks in advance.
gallery.php page... (exclusing database connections etc.)
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM photos");
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
?>
<section class="thumbnails group">
<a href="image.php?id=<?php $info['id'] ?>"> <?php Echo "<img src=http://.../thumbs/tn_".$info['filename'] .">"; }?> </a>
</section>
image.php page...
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM photos WHERE 'id' = ??");
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
?>
<section class="main-image group">
<?php echo "<img src=http://.../images/".$info['filename'] .">"; }?>
</section>
Upvotes: 0
Views: 2858
Reputation: 6106
You can simply pass the ID of the image through in the querystring
<a href="image.php?image=' . $imageID . '"><img src="/path/to/thumbnail"></a>
In your image.php page, you can retrieve the ID like this (assuming it's an integer):
$imageID = intval( $_GET["image"]);
You should then be able to retrieve the path to the image and display it.
Upvotes: 3
Reputation: 502
@ liquorvicar answer is correct one, there's no ambiguity in his answer! well,
try this;
<a href="image.php?id=<?php $info['image_id'] ?>"> <?php Echo "<img src=http://...thumbs/tn_".$info['filename'] .">"; }?> </a>
on image.php page
$id=intval($_REQUEST['id'])
now you have id for that specific image show its related info.
Upvotes: 0