Hi,
I had a topic a while back and the original issue was solved, however now I've gotten stuck a bit further down the road. Essentially, I take all the images from a folder and make a gallery out of them. I turned to the webmonkey tutorial to limit the number of images per page and everything works great, except I'm having trouble starting the array pointer at the appropriate point for a given page.
The only idea I have is to use "array_shift" and iterate it until the page number is reached... but I'm not quite sure how to do that.
Here's my code:
<?php
if(!isSet($_REQUEST["start"])){
$_REQUEST["start"] = 0;
}
$i = $_REQUEST["start"];
$photos_per_page = 12;
$prev_start = $_REQUEST["start"] - $photos_per_page;
$next_start = $_REQUEST["start"] + $photos_per_page;
$exts = array("png","gif","jpg");
$path = "/Users/harrison/Sites/images/photos";
$handle = opendir($path);
$files = array();
$total_photos = 48;
while($file = readdir($handle)) {
if(in_array(substr(strtolower($file),-3),$exts)) {
$files[$file] = filemtime($path."/".$file);
}
}
closedir($handle);
arsort($files);
foreach($files as $key => $value) {
if ($i >= $_REQUEST["start"] && $i < $next_start && $i <= $total_photos && $i >= 0) {
echo "<div class='gallery'>\n<a href='images/photos/display.shtml/".$key."' class='newWindow'>\n<img alt='".$key."' class='gallery' src='images/photos/thumbnails/".$key."' />\n</a>\n</div>\n\n";
$i++;
}
}
?>
<?php
//print out navigation links
if(($_REQUEST["start"] == 0) && ($next_start < $total_photos)){
//you're at the beginning of the photo gallery
?>
<a href="archives/pixels/photographs/index.php?start=<?php print($next_start); ?>">next page</a>»
<?php
}
elseif (($_REQUEST["start"] > 0) && ($next_start < $total_photos)){
//you're in the middle of the photo gallery
?>
«<a href="archives/pixels/photographs/index.php?start=<?php print($prev_start); ?>">prev page</a>
|
<a href="archives/pixels/photographs/index.php?start=<?php print($next_start); ?>">next page</a> »
<?php
}
elseif ((($_REQUEST["start"] > 0) && (($next_start - $photos_per_page) > $total_photos)) or ($_REQUEST["start"] < 0)){
//covering all bases
?>
nav error.
<?php
}
elseif(($_REQUEST["start"] == 0) && ($next_start > $total_photos)){
//you're in a photo gallery with only one page of photos
?>
_
<?php
}
else {
//you're at the end of the photo galley
?>
«
<a href="archives/pixels/photographs/index.php?start=<?php print($prev_start); ?>
">prev page</a>
<?php
}
?>