I'm new at web page coding, and I'm having problems...
Right now I could addapt a code that lists and echoes images from a directory, displaying them with lightbox.
Right now the code displays ALL images from the directory, in rows of 5 images, but WITHOUT limit...
How could I change my code to page results, lets say for example: Just ONE row, with 5 images per PAGE. Then display the usual "Page: 1, 2, 3 ... Next ..." I really don't know how to do it... I've been trying many things without success...
The code goes as follows:
<?php
$page = $_SERVER['PHP_SELF'];
// How many images per row
$maxCols = 5;
// Directory where the albums are stored
$base = "albums";
// Get album title
$get_album = $_GET['album'];
if (!$get_album)
{
$handle = opendir($base);
echo "<div id='albums' class='imageRow'>";
while (($file = readdir($handle))!==FALSE)
{
if (is_dir($base."/".$file) && $file != "." && $file != "..")
{
//$list []= $file;
$img = $file.".jpg"; //Main image from each album.
echo "<div class='image'><a href='$page?album=$file'><img src='thumbnails.php?img=$base/$img' alt='$file' /></a><div class='album'><i>$file</i></div></div>";
}
}
echo "</div>";
closedir($handle);
//$total = count($list);
}
else
{
if (!is_dir($base."/".$get_album) || strstr($get_album,".")!=NULL || strstr($get_album,"/")!=NULL || strstr($get_album,"\\")!=NULL)
{
echo "Album doesn't exist.";
echo "<p /><a href='$page'>Back to albums</a>";
}
else
{
$count = 0;
$handle = opendir($base."/".$get_album);
echo "<div id='images' class='imageRow'>";
while (($file = readdir($handle)) !== FALSE)
{
if ($file != "." && $file !== "..")
{
echo "<div class='image'><a href='$base/$get_album/$file' rel='lightbox[1]' title='$file'><img src='thumbnails.php?img=$base/$get_album/$file' alt='$file' /></a></div>";
$count++;
if($count == $maxCols)
{
echo "</div>";
echo "<div id='images' class='imageRow'>";
$count = 0;
}
$list[] = $file; //Assign the images to a list to allow count.
}
}
echo "</div>";
closedir($handle);
$total = count($list); //Total elements at the album.
//echo "<a href='$page'>Back to albums</a>";
}
}
?>
Any help will be much appreciated!
Many thanks in advance!!