PHP打开文章评论分页

时间:2016-10-11 16:17:12

标签: php pagination

我想对已打开的文章 - index.php?article_id=1分页评论,现在我想将页面重定向到index.php?article_id=1&page=2。我知道有一种方法可以通过获取参数来获取当前网址,只需将&页面附加到其上,但每次单击页面按钮时,它都会生成一个新的get:index.php?article_id=1&page=2&page=2&page=2 ...

我有这个代码,它只适用于1 get param:

if($page == $this->maxpages AND $page != 1 OR $page != $this->maxpages AND $page > 0 AND $page <= $this->maxpages AND $page != 1) {
        $controls .= "<a href='".basename(strtok($_SERVER["REQUEST_URI"],'?'))."?p=".($page-1)."'><-- Back </a>";
    }

    if($this->maxpages > 1 AND $page > 0 AND $page != $this->maxpages AND $page < $this->maxpages) {
        $controls .= "<a href='".basename(strtok($_SERVER["REQUEST_URI"],'?'))."?p=".($page+1)."'> Next --></a>";
    }

    if($controls == "" AND $this->maxpages != 1) {
        $controls .= "<a href='".basename(strtok($_SERVER["REQUEST_URI"],'?'))."?p=1'>On the first page</a>";
    }

复制get:

的代码
        if($page == $this->maxpages AND $page != 1 OR $page != $this->maxpages AND $page > 0 AND $page <= $this->maxpages AND $page != 1) {
        $controls .= "<a href='".basename($_SERVER["REQUEST_URI"])."&p=".($page-1)."'><-- Back </a>";
    }

    if($this->maxpages > 1 AND $page > 0 AND $page != $this->maxpages AND $page < $this->maxpages) {
        $controls .= "<a href='".basename($_SERVER["REQUEST_URI"])."&p=".($page+1)."'> Next --></a>";
    }

    if($controls == "" AND $this->maxpages != 1) {
        $controls .= "<a href='".basename($_SERVER["REQUEST_URI"])."&p=1'>First page</a>";
    }

1 个答案:

答案 0 :(得分:0)

如果您使用$_SERVER['REQUEST_URI'],则会收到整个请求。您必须从文件名创建一个新URL,并添加您需要,更改或相同的每个参数。

$controls .= "<a href='".basename($_SERVER["SCRIPT_NAME"])."?article_id=" . $articleid . "&p=".($page+1)."'> Next --></a>";