PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hey ya guys. I've been working on paging system for an image gallery and I'm having trouble adding a next and previous page link. I think my theory craft on it my be off some.
$images_per_page = 16
//$file_names is a function to get the images of the current working dir in an array
//The javascript:showpage function is how I'm passing a few variables into/out of java, but in this case the value is the image off set. Example page 1=0, page 2=16, page 3=32, and so on.
if ((count($file_names)>$images_per_page || isset($_REQUEST['showimage'])) && $order==0) {
if ($albumpage==1)
echo "Page <font color=red>1</font>";
else
echo "Page <a href=\"javascript:showpage(0)\"><u>1</u></a>";
}
if ($order==0) {
for ($i=$images_per_page;$i<count($file_names);$i+=$images_per_page) {
$p=ceil($i/$images_per_page)+1;
if ($albumpage==$p)
echo " | <font color=red>$p</font>";
else
echo " | <a href=\"javascript:showpage($i)\"><u>$p</u></a>";
}
}
//OUTPUT EXAMPLE: "Page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15"
//What I'm trying to get (assume not on first or last page): "Page [PREVIOUS] 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 [NEXT]
What I'm having trouble with is figuring out where, or how I should put in a next and previous link so make it a little more user friendly.
$images_per_page = 16
//$file_names is a function to get the images of the current working dir in an array
//The javascript:showpage function is how I'm passing a few variables into/out of java, but in this case the value is the image off set. Example page 1=0, page 2=16, page 3=32, and so on.
if ((count($file_names)>$images_per_page || isset($_REQUEST['showimage'])) && $order==0) {
if ($albumpage==1) {
echo "Page <font color=red>1</font>";
} else {
echo "Page ";
echo '[<a href="javascript:showpage(' . ($albumpage-1) . ');">previous</a>]';
echo "<a href=\"javascript:showpage(0)\"><u>1</u></a>";
}
}
if ($order==0) {
for ($i=$images_per_page;$i<count($file_names);$i+=$images_per_page) {
$p=ceil($i/$images_per_page)+1;
if ($albumpage==$p)
echo " | <font color=red>$p</font>";
else
echo " | <a href=\"javascript:showpage($i)\"><u>$p</u></a>";
if ($i == (count($file_names) - 1)) {
if ($albumpage != $p) {
echo '[<a href="javascript:showpage(' . ($albumpage+1) . ');">next</a>]';
}
}
}
}
//OUTPUT EXAMPLE: "Page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15"
//What I'm trying to get (assume not on first or last page): "Page [PREVIOUS] 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 [NEXT]
Brillent. I must not of been awake when trying to look at this.
While I changed it a little bit to work for the offset system (forgot to mention that part), I got the previous linking to work but with what was suggested the next link is not showing up. Here is where I am at.