Hey
I'm been messing around with my code and finally have something working, but I'd like to ask your opinion on something. So I'm trying to create a photo gallery and so far I have 2 links, Previous and Next. Clicking on these will navigate through the pictures. However, at the minute I only have it displaying one predefined picture when you click 'Previous' and another when you click 'Next'. I want to ask your opinion on which way or how would be the best way to loop through the pictures or determine which one is being displayed and then get the next one or previous one in the sequence, depending on which link the user clicks.
My code so far is..
<?php
// directory where photos are kept
$dir = "images/thumbnails/";
$photos = array();
if($handle = opendir($dir))
{
while(false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." )
{
$photos[] = $file;
}
}
closedir($handle);
}
// count the no of photos
$noOfPics = count($photos);
$prev = 2;
$next = 4;
echo '<a href=My_Try_At_Album.php?p=' . $prev . '>Previous!!</a>';
echo '</br></br><a href=My_Try_At_Album.php?p=' . $next . '>Next!!</a>';
if (isset($GET['p']))
{
if (is_numeric($GET['p']))
{
$picIndex = $_GET['p'];
}
else
{
$picIndex = 1;
}
$currentPic = $photos[$picIndex];
echo '</br></br><img src="' . $dir . $currentPic .'"/>';
}
?>
Thanks again :-)