PHP分页问题

时间:2012-02-21 03:20:07

标签: php pagination

我似乎遇到了非常恼人的问题,我找到了一个精彩的分页脚本,但它只是给我带来了麻烦,尽管设置时间很长,我还是按照一个好的标准运行,但脚本没有'似乎明白我想控制“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;
            }
        }

请注意,上面是完整编码的片段,您可以在此地址找到代码的完整副本:http://net.tutsplus.com/tutorials/php/how-to-paginate-data-with-php

好吧,所以我遇到的问题是我通过_GET ['ipp']传递给变量ipp的任何东西,它似乎完全忽略了,但是_GET ['ipp']的回声非常好......

例如,news.php?page = 2&amp; ipp = 5&amp; id = 3。当我将IPP从5更改为另一个数字时,它将完全忽略我已经这样做并保持IPP(每页项目数)为5的事实?我现在对脚本非常困惑,它正是我正在寻找的东西,但似乎不能按我的方式工作。

感谢任何潜在的帮助者,感谢您的光临。

最好的问候

1 个答案:

答案 0 :(得分:0)

您会意识到,如果您更改 $ _ GET ['ipp] ,其他值可能不再相关,而且如果不知道还有其他值,则不知道还有其他值。

我的建议是解决你的问题,一些基本的调试:

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
  // ...
}