php分页问题
<?php/**Createdon2010-5-26**Tochangethetemplateforthisgeneratedfilegoto*Window-Prefer...
<?php
/*
* Created on 2010-5-26
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
function _PAGEGET($total,$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"];
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";
}
$lastpage = ceil($total/$displaypg);
$page = min($lastpage, $page);
$prepg = $page-1;
$nextpg = ($page == $lastpage ? 0 : $page+1);
$firstcount = ($page-1)*$displaypg;
//开始分页导航代码
$pagenav = "显示第<b>" . ($total ? ($firstcount+1) : 0) . "</b>-<b>" . min($firstcount+$displaypg, $total) . "</b>条记录,共".$total."条记录" ;
//如果只有一页则跳出函数
if($lastpage<=1)
return false;
$pagenav .= " <a href='".$url."=1'>首页</a> ";
if($prepg)
$pagenav .= "<a href='".$url."=".$prepg."'>前页</a>";
else
$pagenav .= " 前页 ";
if($nextpg)
$pagenav .= "<a href='".$url."=".$nextpg."'>后页</a>";
else
$pagenav .= " 后页 ";
$pagenav .= " <a href='".$url."=".$lastpage."'>尾页</a> ";
$pagenav .= "到第 <select name='topage' size='1' onchange='window.location=\"$url=\"+this.value'>\n";
for($i=1; $i<=$lastpage; $i++){
if($i == $page)
$pagenav .= "<option value='$i' selected>$i</option>\n";
else
$pagenav .= "<option value='$i'>$i</option>\n";
}
$pagenav .= "</select> 页,共 $lastpage 页";
}
include("conn.php");
mysql_query("SET names 'GBK'");
$result = mysql_query("SELECT * FROM test");
$total = mysql_num_rows($result);
_PAGEGET($total, 5);
echo $pagenav;
$SQL = "SELECT * FROM test LIMIT $firstcount,$displaypg;";
$query = mysql_query($SQL);
while ($row = mysql_fetch_array($query)){
echo "<hr/><b>".$row[name]." | ".$row[sex]."</b>";
}
?>
这个程序错在哪里了?我找了半天也没找出来。请高手 帮帮忙。不能分页。只能显示一页。谢谢大家了。。。 展开
/*
* Created on 2010-5-26
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
function _PAGEGET($total,$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"];
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";
}
$lastpage = ceil($total/$displaypg);
$page = min($lastpage, $page);
$prepg = $page-1;
$nextpg = ($page == $lastpage ? 0 : $page+1);
$firstcount = ($page-1)*$displaypg;
//开始分页导航代码
$pagenav = "显示第<b>" . ($total ? ($firstcount+1) : 0) . "</b>-<b>" . min($firstcount+$displaypg, $total) . "</b>条记录,共".$total."条记录" ;
//如果只有一页则跳出函数
if($lastpage<=1)
return false;
$pagenav .= " <a href='".$url."=1'>首页</a> ";
if($prepg)
$pagenav .= "<a href='".$url."=".$prepg."'>前页</a>";
else
$pagenav .= " 前页 ";
if($nextpg)
$pagenav .= "<a href='".$url."=".$nextpg."'>后页</a>";
else
$pagenav .= " 后页 ";
$pagenav .= " <a href='".$url."=".$lastpage."'>尾页</a> ";
$pagenav .= "到第 <select name='topage' size='1' onchange='window.location=\"$url=\"+this.value'>\n";
for($i=1; $i<=$lastpage; $i++){
if($i == $page)
$pagenav .= "<option value='$i' selected>$i</option>\n";
else
$pagenav .= "<option value='$i'>$i</option>\n";
}
$pagenav .= "</select> 页,共 $lastpage 页";
}
include("conn.php");
mysql_query("SET names 'GBK'");
$result = mysql_query("SELECT * FROM test");
$total = mysql_num_rows($result);
_PAGEGET($total, 5);
echo $pagenav;
$SQL = "SELECT * FROM test LIMIT $firstcount,$displaypg;";
$query = mysql_query($SQL);
while ($row = mysql_fetch_array($query)){
echo "<hr/><b>".$row[name]." | ".$row[sex]."</b>";
}
?>
这个程序错在哪里了?我找了半天也没找出来。请高手 帮帮忙。不能分页。只能显示一页。谢谢大家了。。。 展开
3个回答
展开全部
你确定你的数据库里记录条数大于5?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
错误很明显,你的
_PAGEGET没有产生网页输出,也没有返回值。
(1) 请 把
_PAGEGET($total, 5);
改成:$pagenav=_PAGEGET($total, 5);
(2) 在FUNCTION 的最末尾加入 return $pagenav;
function _PAGEGET($total,$displaypg = 20,$url = ''){
................................
return $pagenav;
}
_PAGEGET没有产生网页输出,也没有返回值。
(1) 请 把
_PAGEGET($total, 5);
改成:$pagenav=_PAGEGET($total, 5);
(2) 在FUNCTION 的最末尾加入 return $pagenav;
function _PAGEGET($total,$displaypg = 20,$url = ''){
................................
return $pagenav;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询