Page 1 of 1

Paging system help

Posted: Sun Sep 12, 2010 6:52 pm
by angelicodin
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.

Code: Select all

$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.

Any thoughts, or other questions?

Re: Paging system help

Posted: Sun Sep 12, 2010 8:08 pm
by Jonah Bron
This might work, try it. The conditions for whether a previous link should be there were already there, so that part was easy.

Code: Select all

$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] 

Re: Paging system help

Posted: Mon Sep 13, 2010 3:22 pm
by angelicodin
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.

Code: Select all

        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 * 16) - 32) . ');">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>]';
                    }
                }
            }
        }
And now I'm off to troll for people I can help at the same time ;p

Re: Paging system help

Posted: Mon Sep 13, 2010 4:06 pm
by angelicodin
I totally figured it out. Got some coffee and went over it all again >_<

Code: Select all

if( $albumpage < ((count($file_names)/$images_per_page))  ){
    echo '[<a href="javascript:showpage(' . ($albumpage * 16) . ');">next</a>]';
}
They really should make us coders an IV drip of coffee so we can function()