Does this make the url be savable? Like if I change the url of a certain picture on the page that randomly selects one and a user saves that url and opens it the next day, will it show the same picture it did when he first saw it?
Yeah, it would be enough to just use the PHP $_GET function to show a certain picture, but it's still a little complicated..
My tip is that you insert every image name (example, image.jpg) in a database (the ID will be set automatically if you make it auto increase), and then you use the id of the database row to decide which picture to show.
For example:
<?php
$image_id=$_GET['imageid']; //The ID of the image
$get_image=mysql_query("SELECT * FROM `images` WHERE `image_id`='{$image_id}'"); //Check if the ID exists in the database
$array_image=mysql_fetch_array($get_image); //Array the query
$get_all_images=mysql_query("SELECT * FROM `images`"); //count all images so that we can check if the "next" button should show or not
$count_images=mysql_num_rows($get_all_images); //Count all the images
if(mysql_num_rows($get_image)==0) //If the imageID is not found in the database, echo an error
{
echo "Image not found";
}
else //Else, show the image
{
?>
<div class="image">
<img src="images/<?php echo $array_image['image_name']; ?>" alt="<?php $array_image['image_name']; ?>" /> <!-- I set the directory as "images" as you can se, and then the name of the picture, which I assume is, for example, test.jpg -->
</div>
<?php
}
if($image_id>1)//If the current image_id is greater than 1, show the previous button
{
?>
<a href="?imageid=<?php echo $imageid--; ?>">Previous</a>
<?php
}
if($image_id<$count_images) //If the current image_id is smaller than the total amount of images in the database, show the next button
{
?>
<a href="?imageid=<?php echo $imageid++; ?>">Next</a>
<?php
}
?>Now if you try to type www.example.com?imageid=20, you should see the picture that has ID 20 in the database.
Is this what you want?
Regards
/Feelay | Nanashi
Edited by Feelay, 13 August 2010 - 05:53 PM.