简体   繁体   中英

PHP Pagination Issues

I seem to be having very annoying problems, I have found a brilliant paginations script however it is doing me nothing but trouble, despite a long set-up time, I got it working to a ok standard, however the script doesn't seem to understand that I want to control "ipp".

// PAGINATOR \\

    var $items_per_page;
    var $items_total;
    var $current_page;
    var $num_pages;
    var $mid_range;
    var $low;
    var $limit;
    var $return;
    var $default_ipp = 5;
    var $querystring;
    var $ipp_array;
    var $html;


    function Paginator()
    {
        $this->current_page = 1;
        $this->mid_range = 7;
        $this->ipp_array = array(10,25,50,100,'All');

    }

    function paginate($html)
    {
        if(!isset($_GET['ipp']))
        {
            $this->items_per_page = $this->default_ipp;
        } else {
        $this->items_per_page = $_GET['ipp'];
        }
        if($_GET['ipp'] == 'All')
        {
            $this->num_pages = 1;
            $this->items_per_page = $this->default_ipp;
        }
        else
        {
            if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
            $this->num_pages = ceil($this->items_total/$this->items_per_page);
        }
        if(!isset($_GET['page']) OR $_GET['page'] == '')
        {
            $this->current_page = 1; // must be numeric > 0
        } else {
        $this->current_page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1 ; // must be numeric > 0
        }
        $prev_page = $this->current_page-1;
        $next_page = $this->current_page+1;
        if($_GET)
        {
            $args = explode("&",$_SERVER['QUERY_STRING']);
            foreach($args as $arg)
            {
                $keyval = explode("=",$arg);
                if($keyval[0] != "page" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg . $html;
            }
        }

Please note, the above is a snip of the full coding, you can find a full copy of the code at this address: http://net.tutsplus.com/tutorials/php/how-to-paginate-data-with-php

Okay, so the issue I am having is whatever I pass to the variable ipp through the _GET['ipp'], it seems to totally ignore, however echoing _GET['ipp'] works perfectly fine..

For example, news.php?page=2&ipp=5&id=3. When I change the IPP from 5 to another number, it will totally ignore the fact that I have done that and keep the IPP(Items per page) at 5? I am very confused with the script now, its exactly what I am looking for however just seems to not work my way.

Thank you for any potential helpers, and thanks for having a look.

Best Regards

You realize if you change $_GET['ipp] the other values may no longer be relevant, plus who knows what else is going on without running through the code.

My suggestion to solve your problem, some basic debugging:

if($_GET) {
  // add some debugging here to see what all the calculated values are
  var_dump(array(
    $this->items_per_page,
    $this->items_total,
    $this->current_page,
    $this->num_pages,
    $this->mid_range,
    $this->low,
    $this->limit,
    $this->return,
    $this->default_ipp,
    $this->querystring,
    $this->ipp_array,
  ));

  // other code already in this block
  // ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM