The code below should at least get you started and give you an idea on how to approach the situation.
Basically you set up your pagesize and then figure out how many pages you'll have by dividing your image count by the
specified page count (25 in this case).
So what we do initially is try to get the $_POST value at 'currentpage'. This variable will be posted back to the same page
on button click so we can load the appropriate images.
once we know the page to load (current page) we can start to draw the images at that offset in the $images array.
as we echo the images, we have to make sure that the index is less than the count() of the $images array.
if we reach the end prematurely (Ex. last page only has 3 images) then simply break the loop.
at the end we'll echo our buttons that are used for the page navigation. We just loop from 1 to totalpages
and if we hit the currentpage, just echo a span instead (visual for user of what page they're on).
I used a form and simply use javascript to set the hidden field and call the .submit().
Hope this helps,
Justin
Code:
<?php
//path to current directory
$directory = "./";
//get all files with a .jpg extension
$images = glob($directory . "*.jpg");
$pageitemcount = 25;
$totalpages = intval(count($images)/$pageitemcount);
$totalpages=$totalpages==0?1:$totalpages;
$currentpage = !isset($_POST['currentpage'])?1:intval($_POST['currentpage']);
?>
<html>
<body bgcolor="#EEEEEE" style='font-family: Arial'>
<?php
echo("<p><b><font face='arial black,arial' size='6' color='#004488'>G4IJE SSTV Archive</font></b></p>");
echo("<p><a href='http://www.classicsstv.com/rxpics.htm'>Click here to return to the main SSTV pics page</a></p>");
$i = $currentpage>1?($currentpage * $pageitemcount)-1:0
for($i;$i < $pageitemcount; $i++){
if($i < count($images)){
echo(sprint("<img src='%s' border='1' hspace='2' vspace='2'/>",$images[$i]));
}
}
echo("<br />");
?>
<form name='pagenav' method="post" action="thispage.php" enctype='...' >
<?php
for($j=1;$j<=$totalpages;$j++){
if($j == $currentpage){
echo(sprint("<span>%d</span>",$j));
}
else{
echo(sprintf("<input type='button' onclick=\"loadselection('%d')\" value='%d' />",$j,$j));
}
}
echo("<input type="hidden" id='selectedpage' name='currentpage' />");
?>
</form>
<?php
echo("<br /><p><a href='http://www.classicsstv.com/rxpics.htm'>Click here to return to the main SSTV pics page</a></p>");
?>
<script type='text/javascript'>
function loadselection(value){
document.forms['pagenav'].currentpage.value = value;
document.forms['pagenav'].submit();
}
</script>
</body>
</html>
in progess...