求指导一下我这个php翻页代码~
<?php$link=mysql_connect("localhost","root","");//连接数据库mysql_select_db("lims");//选择哪个...
<?php
$link = mysql_connect("localhost","root",""); //连接数据库
mysql_select_db("lims");//选择哪个数据库
mysql_query("set names gbk"); //设置数据库字符编码为中文
$sql = mysql_query("select * from loadup");
$pagesize = 5; //每页显示信息条数
$sum = mysql_num_rows($sql); //一共有多少条数据
$count = ceil($sum/$pagesize);//求出一共有多少页
echo $count;
$max_p = $count;
if(empty($_GET["page"]) || $_GET["page"]<0){
$page = 1;
}else{
$page = $_GET["page"];
}
$off = ($page-1)*$pagesize; //求出数据库查询的第一个数据
$he = mysql_query("select *from loadup limit $off,$pagesize");//按照off开始,到pagesize规律显示
while($row = mysql_fetch_array($he)){
?>
<?php echo $row["id"];?>
<?php echo $row["title"]."<br/>";?>
<?php
}
//非首页和首页,“首页和上一页”的显示
if($page!=1){
$key.="<span><a href=\"".$_SERVER['PHP_SELF']."?page=1"."\">首页 </a></span>";
$key.="<span><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\">上一页 </a></span>";
}else{
$key.="<span>首页 </span>";
$key.="<span>上一页 </span>";
}
//最后一页和非最后一页,“下一页和最后一页”的显示
if($i!=$count){
$key.="<span><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\">下一页</a></span>";
$key.="<span><a href=\"".$_SERVER['PHP_SELF']."?page=$max_p\">最后一页</a></span>";
}else{
$key.="<span>下一页</span>";
$key.="<span>最后一页</span>";
}
?>
<?php echo $key;?>
总页码只有3页,而到第三页后点下一页仍然出现翻页工具条但没数据~
请问如何改~ 展开
$link = mysql_connect("localhost","root",""); //连接数据库
mysql_select_db("lims");//选择哪个数据库
mysql_query("set names gbk"); //设置数据库字符编码为中文
$sql = mysql_query("select * from loadup");
$pagesize = 5; //每页显示信息条数
$sum = mysql_num_rows($sql); //一共有多少条数据
$count = ceil($sum/$pagesize);//求出一共有多少页
echo $count;
$max_p = $count;
if(empty($_GET["page"]) || $_GET["page"]<0){
$page = 1;
}else{
$page = $_GET["page"];
}
$off = ($page-1)*$pagesize; //求出数据库查询的第一个数据
$he = mysql_query("select *from loadup limit $off,$pagesize");//按照off开始,到pagesize规律显示
while($row = mysql_fetch_array($he)){
?>
<?php echo $row["id"];?>
<?php echo $row["title"]."<br/>";?>
<?php
}
//非首页和首页,“首页和上一页”的显示
if($page!=1){
$key.="<span><a href=\"".$_SERVER['PHP_SELF']."?page=1"."\">首页 </a></span>";
$key.="<span><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\">上一页 </a></span>";
}else{
$key.="<span>首页 </span>";
$key.="<span>上一页 </span>";
}
//最后一页和非最后一页,“下一页和最后一页”的显示
if($i!=$count){
$key.="<span><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\">下一页</a></span>";
$key.="<span><a href=\"".$_SERVER['PHP_SELF']."?page=$max_p\">最后一页</a></span>";
}else{
$key.="<span>下一页</span>";
$key.="<span>最后一页</span>";
}
?>
<?php echo $key;?>
总页码只有3页,而到第三页后点下一页仍然出现翻页工具条但没数据~
请问如何改~ 展开
3个回答
展开全部
自己看下 不懂再问
<?php
header ( 'content-type:text/html;charset=utf-8' );
function paginator($currentPage, $totalPages, $attachParam = null, $pageString = 'page') {
if ($currentPage == 1) {
$first = '最前页';
$prev = '上一页';
$next = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=' . ($currentPage + 1) . '&' . $attachParam . '">下一页</a>';
$last = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=' . $totalPages . '&' . $attachParam . '">最后页</a>';
}
if ($currentPage == $totalPages) {
$first = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=1&' . $attachParam . '">最前页</a>';
$prev = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=' . ($currentPage - 1) . '&' . $attachParam . '">上一页</a>';
$next = '下一页';
$last = '最前页';
}
if ($currentPage > 1 && $currentPage < $totalPages) {
$first = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=1&' . $attachParam . '">最前页</a>';
$prev = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=' . ($currentPage - 1) . '&' . $attachParam . '">上一页</a>';
$next = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=' . ($currentPage + 1) . '&' . $attachParam . '">下一页</a>';
$last = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=' . $totalPages . '&' . $attachParam . '">最后页</a>';
}
return $first . ' ' . $prev . ' ' . $next . ' ' . $last;
}
$page = $_GET['page'];
if(!isset($page)) $page = 1;
echo paginator ( $page, 15 , 'id=1&pid=7' );
<?php
header ( 'content-type:text/html;charset=utf-8' );
function paginator($currentPage, $totalPages, $attachParam = null, $pageString = 'page') {
if ($currentPage == 1) {
$first = '最前页';
$prev = '上一页';
$next = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=' . ($currentPage + 1) . '&' . $attachParam . '">下一页</a>';
$last = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=' . $totalPages . '&' . $attachParam . '">最后页</a>';
}
if ($currentPage == $totalPages) {
$first = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=1&' . $attachParam . '">最前页</a>';
$prev = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=' . ($currentPage - 1) . '&' . $attachParam . '">上一页</a>';
$next = '下一页';
$last = '最前页';
}
if ($currentPage > 1 && $currentPage < $totalPages) {
$first = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=1&' . $attachParam . '">最前页</a>';
$prev = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=' . ($currentPage - 1) . '&' . $attachParam . '">上一页</a>';
$next = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=' . ($currentPage + 1) . '&' . $attachParam . '">下一页</a>';
$last = '<a href="' . $_SERVER ['PHP_SELF'] . '?' . $pageString . '=' . $totalPages . '&' . $attachParam . '">最后页</a>';
}
return $first . ' ' . $prev . ' ' . $next . ' ' . $last;
}
$page = $_GET['page'];
if(!isset($page)) $page = 1;
echo paginator ( $page, 15 , 'id=1&pid=7' );
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if($page!=$count & $page<=$count) 第二个判断改一下试试
追问
非常感谢,请看楼上问题的补充~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询