Home  >  Article  >  Backend Development  >  有关PHP分页显示的有关问题

有关PHP分页显示的有关问题

WBOY
WBOYOriginal
2016-06-13 11:43:22885browse

有关PHP分页显示的问题
我在听PHP100视频中有关介绍分页原理的介绍。根据提供的代码,进行运行后发现换页无法进行,url还一直显示?page=2page=3page=4等,刚开始找到原因是因为ereg_replace函数已经在5.3的版本中不用,改为preg_replace还是不行,请麻烦高手给予解答。谢谢。

代码:

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 = preg_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 = "显示第 " . ($totle ? ($firstcount +1) : 0) . "-" . min($firstcount + $displaypg, $totle) . " 条记录,共 $totle 条记录";
//如果只有一页则跳出函数:
if ($lastpg return false;
$pagenav .= " 首页 ";
if ($prepg)
$pagenav .= " 前页 ";
else
$pagenav .= " 前页 ";
if ($nextpg)
$pagenav .= " 后页 ";
else
$pagenav .= " 后页 ";
$pagenav .= " 尾页 ";
//下拉跳转列表,循环列出所有页码:
$pagenav .= " 到第  页,共 $lastpg 页";
}
include("conn.php");
$result=mysql_query("SELECT * FROM `p_newsbase`");
$total=mysql_num_rows($result);
//调用pageft(),每页显示10条信息(使用默认的20时,可以省略此参数),使用本页URL(默认,所以省略掉).
_PAGEFT($total,1);
echo $pagenav;
$result=mysql_query("SELECT * FROM `p_newsbase` limit $firstcount,$displaypg ");
while($row=mysql_fetch_array($result)){
echo "


".$row['author']." | ".$row['title'];
}

?
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