Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

PAGING

Name: Anonymous 2008-05-18 14:46

how do you solve this age old problem of rounding off a number

$pages = $returned_rows/$items_per_page

when i use php functions to round the result off i end up with 1 for example if i have 7 results and 5 items on every page

this happens from time to time, whenever uneven numbers come up, so how do you guys solve this? i was going to look at other products such as vbulletin but i figured this could be a good topic as a break from all the meme spam

Name: Anonymous 2008-05-18 14:51

lol i think i solved it with ceil() but i'm sure more situations will arise where odd numbers cause problems with paging

Name: Anonymous 2008-05-18 14:56

SAGING

Name: Anonymous 2008-05-18 15:11

>>1
Fucking idiot.

Name: Anonymous 2008-05-18 15:25

but i figured this could be a good topic as a break from all the meme spam
*facepalm*

Name: Anonymous 2008-05-18 15:41

pages = int((items + items_per_page - 1) / items_per_page)

you are dumb. meme spawn is protection from you.

Name: Anonymous 2008-05-18 16:41

$FUZZ_FACTOR = rand();
pages = floor($returned_rows/$items_per_page * FUZZ_FACTOR)

Name: Anonymous 2008-05-18 17:42

You solve it by haxing my anus

Name: Anonymous 2008-05-18 17:48


MoronFactory.getNewMoron(null, null, null, null, null, null, null, 1, null, null, null, null, "", null, null, null, null, this, null, null, null, null, null, 0);

Name: Anonymous 2008-05-18 19:07

>>9
""
String.Empty
0
Integer.getIntegerFactory().getInteger("0")
null
NullFactory.getNullFactory(null, 0).getNull(null, null, null)

Name: Anonymous 2008-05-19 4:55

Here's a shitty class I wrote to handle pagination:

<?php
    /*
    | Currently, the paginator assumes we're using
    |    $_GET['perpage']
    |    $_COOKIE['perPage']
    | An option to change this may be added in future versions.
    |
    | Also, when showing 'All' rows, we limit to 2 ^ 20 rows (roughly 1m)
    | We could simply omit the 'limit' statement in SQL, but this is
    | slightly safer, as if there are >1m rows, the page will actually stop
    | loading at some point.
    */

    class paginator {
        // object - cookie management
        var $cookie;
        // array - list of possible values per page
        var $perPageArray;
        // int - max results per page
        var $maxPerPage;
        // int - page start (row)
        var $pageStart;
        // int - current page
        var $currentPage;

        // automatically updates local vars
        function config(&$cookie,$perPageArray,$maxPerPage,$pageNum) {
            $this->cookie = $cookie;
            $this->perPageArray = $perPageArray;
            $this->maxPerPage = $this->setPerPage($maxPerPage);
           
            // we have to account for the fact that pages are displayed starting at 1
            // but in the code, start at 0
            $this->currentPage = ($pageNum > 0) ? $pageNum - 1 : 0;
            $this->pageStart = $this->currentPage * $this->maxPerPage;
        }
       
        // sets max results per page
        // basically, this gets its own function to keep config() from getting too messy
        function setPerPage($maxPerPage) {
            // this is a hard default, since $maxPerPage should come from a config variable
            $maxPerPage = ($maxPerPage > 0) ? $maxPerPage : 20;
           
            // we assume $_GET uses a non-camel-case perPage, due to URL consistency
           
            // perPage has a new value
            if($_GET['perpage'] != '') {
                if($_GET['perpage'] == 'All') {
                    $perPage = pow(2,20); // 2 ^ 20
                    $this->cookie->create('perPage',$_GET['perpage']);
                } elseif($_GET['perpage'] > 0) {
                    $perPage = $_GET['perpage'];
                    $this->cookie->create('perPage',$_GET['perpage']);
                }
            }
           
            // checking for perPage as set by a cookie
            // we can keep this separate from the above, since
            // the cookie class automatically assigns new variables to $_COOKIE
            if($_COOKIE['perPage'] != '') {
                if($_COOKIE['perPage'] == 'All') {
                    $perPage = pow(2,20); // 2 ^ 20
                } elseif($_COOKIE['perPage'] > 0) {
                    $perPage = $_COOKIE['perPage'];
                }
            // default perPage value
            } else {
                // we set a cookie incase the default somehow changes between pages
                $perPage = $maxPerPage;
                $this->cookie->create('perPage',$maxPerPage);
            }
           
            return $perPage;
        }
       
        // int - array of pages
        function getPageArray($totalRows) {
            $numberOfPages = ($this->maxPerPage > 0) ? ceil($totalRows / $this->maxPerPage) : 0;
            if($numberOfPages < 1) $numberOfPages = 1;
            return range(1,$numberOfPages);
        }
       
        // int - page start (row)
        function getPageStart() { return $this->pageStart; }
       
        // int or string - rows per page ('All' is represented as a string)
        function getPerPage($returnAsString = false) {
            if($returnAsString == false) {
                return $this->maxPerPage;
            } else {
                return ($_GET['perpage'] == 'All' || $_COOKIE['perPage'] == 'All') ? 'All' : $this->maxPerPage;
            }
        }
       
        // array - list of possible values per page
        function getPerPageArray() { return $this->perPageArray; }
       
        // int - current page (incremented by 1 to account for the display offset)
        function getCurrentPage() { return $this->currentPage + 1; }
    }
?>

Name: Anonymous 2008-05-19 4:57

>>11
Before anyone comes to HAX MY ANUS, I don't use this anymore.

Name: Anonymous 2008-05-19 7:49

>>11
perp age

Name: Anonymous 2008-05-19 9:22

>>11
ENTERPRISE

Name: hax my anus 2008-05-19 9:29

>>12
wat

Name: Anonymous 2008-05-19 9:31

I PAGE MY ANUS

Name: Anonymous 2010-12-06 9:20

Back to /b/, ``GNAA Faggot''

Name: Sgt.Kabukiman樕ˊ 2012-05-23 5:52

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List