Home >Backend Development >PHP Tutorial >php分页遇到的有关问题

php分页遇到的有关问题

WBOY
WBOYOriginal
2016-06-13 10:36:35890browse

php分页遇到的问题
刚学习php,在php100下载了视频教程,可是根据教程里第十三讲给的分页demo,发现运行出错,请大虾给分析下什么原因呢?数据库表为test,字段包括:id、name、sex;运行下面的demo,可现实第一页内容,但是点击下一页的时候不翻页。url地址为http://localhost/bbs2/page.php?page=2,再点击下一页url为http://localhost/bbs2/page.php?page=2&page=2;这个地址就不对了,应该是http://localhost/bbs2/page.php?page=3吧。

HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php function _PAGEFT($totle, $displaypg = 20, $url = '') {        global $page, $firstcount, $pagenav, $_SERVER;        $GLOBALS["displaypg"] = $displaypg;        if (!$page)            $page = 1;        if (!$url) {            $url = $_SERVER["REQUEST_URI"];        }        //URL分析:        $parse_url = parse_url($url);        $url_query = $parse_url["query"]; //单独取出URL的查询字串        if ($url_query) {            $url_query = ereg_replace("(^|&)page=$page", "", $url_query);            $url = str_replace($parse_url["query"], $url_query, $url);            if ($url_query)                $url .= "&page";            else                $url .= "page";        } else {            $url .= "?page";        }        $lastpg = ceil($totle / $displaypg); //最后页,也是总页数        $page = min($lastpg, $page);        $prepg = $page -1; //上一页        $nextpg = ($page == $lastpg ? 0 : $page +1); //下一页        $firstcount = ($page -1) * $displaypg;        //开始分页导航条代码:        $pagenav = "显示第 <B>" . ($totle ? ($firstcount +1) : 0) . "-<b>" . min($firstcount + $displaypg, $totle) . "</b> 条记录,共 $totle 条记录";        //如果只有一页则跳出函数:        if ($lastpg 首页 ";        if ($prepg)            $pagenav .= " <a href="%24url=%24prepg">前页</a> ";        else            $pagenav .= " 前页 ";        if ($nextpg)            $pagenav .= " <a href="%24url=%24nextpg">后页</a> ";        else            $pagenav .= " 后页 ";        $pagenav .= " <a href="%24url=%24lastpg">尾页</a> ";        //下拉跳转列表,循环列出所有页码:        $pagenav .= " 到第 <select name="topage" size="1" onchange='window.location=\"$url=\"+this.value'>\n";        for ($i = 1; $i $i\n";            else                $pagenav .= "<option value="$i">$i</option>\n";        }        $pagenav .= "</select> 页,共 $lastpg 页";    }include("conn.php");$result=mysql_query("SELECT * FROM `test`");$total=mysql_num_rows($result);//调用pageft(),每页显示10条信息(使用默认的20时,可以省略此参数),使用本页URL(默认,所以省略掉)。_PAGEFT($total,5);echo $pagenav;$result=mysql_query("SELECT * FROM `test` limit $firstcount,$displaypg ");while($row=mysql_fetch_array($result)){echo "<hr><b>".$row[name]." | ".$row[sex];}?></b>


------解决方案--------------------
这个教程真是害人,太不靠谱了。 不如你在网上找找源码自己改改看
找了半天没看见 $_GET['page'], LIMIT 这两个分页必需词汇
------解决方案--------------------
PHP code
$nowPage = is_numeric($_GET['page']) ? $_GET['page'] : 1; // 当前页$displaypg = 5; //每页显示五个条目;firstcount = ($nowPage-1)*$displaypg;$result=mysql_query("SELECT * FROM `test` limit $firstcount,$displaypg ");<br><font color="#e78608">------解决方案--------------------</font><br>不翻页是你的page没有得到<br><br>这分页程序够雷人的<br><br>太坑人了<br><br>写那么大一片<br><br>去掉一半运行都不会有问题<br><font color="#e78608">------解决方案--------------------</font><br>
探讨
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn