php分页点击下一页就没了
目录页原始地址:http://127.0.0.1/xuanchuanpian/mulu.php?leibie='关于我们'点击下一页时的地址:http://127.0.0...
目录页原始地址:http://127.0.0.1/xuanchuanpian/mulu.php?leibie='关于我们'
点击下一页时的地址:http://127.0.0.1/xuanchuanpian/mulu.php?page=2
我的分页代码是:<?php
if (isset($_GET['leibie'])){
$leibie=$_GET['leibie'];}
//$sql="select * from wenzhang where leibie=".$leibie."";
//$query=mysql_query($sql);
//while ($rs=mysql_fetch_array($query)){
$perpagenum = 10;
//查询数据库中一共有多少条数据
$total = mysql_fetch_array(mysql_query("select count(*) from wenzhang where leibie=".$leibie.""));
$Total = $total[0]; //
$Totalpage = ceil($Total/$perpagenum);//上舍,取整
if(!isset($_GET['page'])||!intval($_GET['page'])||$_GET['page']>$Totalpage)//page可能的四种状态
{
$page=1;
}
else
{
$page=$_GET['page'];//如果不满足以上四种情况,则page的值为$_GET['page']
}
$startnum = ($page-1)*$perpagenum;//开始条数
$sql = "SELECT * FROM `wenzhang` where leibie=".$leibie." order by shijian desc limit $startnum,$perpagenum";//查询出所需要的条数
//echo $sql." ";
$rs = mysql_query($sql);
$contents = mysql_fetch_array($rs);
if($total)//如果$total不为空则执行以下语句
{
do
{
$id = $contents['wenzhangid'];
//echo $id;
$biaoti = $contents['biaoti'];
if (strlen($biaoti)>10){
$biaoti=substr($biaoti,1,10)."...";
}
$neirong = $contents['neirong'];
if (strlen($neirong)>26){
$neirong=substr($neirong,1,26)."...";
}
$shijian = $contents['shijian'];
?>
<li>
<?php echo $contents['biaoti'];?></li><div align="center">
<?php
}
while($contents = mysql_fetch_array($rs));//do....while
$per = $page - 1;//上一页
$next = $page + 1;//下一页
echo "显示第 <B>" . ($Total ? ($startnum +1) : 0) . "</B>-<B>" . min($startnum + $perpagenum, $Total) . "</B> 条记录 ";
echo "共有".$Total."条记录,每页".$perpagenum."条";
if($page != 1)
{
echo "<a href='".$_SERVER['PHP_SELF']."'>首页</a>";
echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$per."'> 上一页</a>";
}
if($page != $Totalpage)
{
echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$next."'> 下一页</a>";
echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$Totalpage."'> 尾页</a>";
}
$myurl=$_SERVER['PHP_SELF'].'?page';
//下拉跳转列表,循环列出所有页码:
$pagenav .= " 到第 <select name='topage' size='1' onchange='window.location=\"$myurl=\"+this.value'>\n";
for ($i = 1; $i <= $Totalpage; $i++) {
if ($i == $page)
$pagenav .= "<option value='$i' selected>$i</option>\n";
else
$pagenav .= "<option value='$i'>$i</option>\n";
}
$pagenav .= "</select> 页,共". $Totalpage ."页";
echo $pagenav;
}
else //如果$total为空则输出没有记录
{
echo "没有记录";
}
?>希望高手能给解决一下,最好能详细点,谢谢 展开
点击下一页时的地址:http://127.0.0.1/xuanchuanpian/mulu.php?page=2
我的分页代码是:<?php
if (isset($_GET['leibie'])){
$leibie=$_GET['leibie'];}
//$sql="select * from wenzhang where leibie=".$leibie."";
//$query=mysql_query($sql);
//while ($rs=mysql_fetch_array($query)){
$perpagenum = 10;
//查询数据库中一共有多少条数据
$total = mysql_fetch_array(mysql_query("select count(*) from wenzhang where leibie=".$leibie.""));
$Total = $total[0]; //
$Totalpage = ceil($Total/$perpagenum);//上舍,取整
if(!isset($_GET['page'])||!intval($_GET['page'])||$_GET['page']>$Totalpage)//page可能的四种状态
{
$page=1;
}
else
{
$page=$_GET['page'];//如果不满足以上四种情况,则page的值为$_GET['page']
}
$startnum = ($page-1)*$perpagenum;//开始条数
$sql = "SELECT * FROM `wenzhang` where leibie=".$leibie." order by shijian desc limit $startnum,$perpagenum";//查询出所需要的条数
//echo $sql." ";
$rs = mysql_query($sql);
$contents = mysql_fetch_array($rs);
if($total)//如果$total不为空则执行以下语句
{
do
{
$id = $contents['wenzhangid'];
//echo $id;
$biaoti = $contents['biaoti'];
if (strlen($biaoti)>10){
$biaoti=substr($biaoti,1,10)."...";
}
$neirong = $contents['neirong'];
if (strlen($neirong)>26){
$neirong=substr($neirong,1,26)."...";
}
$shijian = $contents['shijian'];
?>
<li>
<?php echo $contents['biaoti'];?></li><div align="center">
<?php
}
while($contents = mysql_fetch_array($rs));//do....while
$per = $page - 1;//上一页
$next = $page + 1;//下一页
echo "显示第 <B>" . ($Total ? ($startnum +1) : 0) . "</B>-<B>" . min($startnum + $perpagenum, $Total) . "</B> 条记录 ";
echo "共有".$Total."条记录,每页".$perpagenum."条";
if($page != 1)
{
echo "<a href='".$_SERVER['PHP_SELF']."'>首页</a>";
echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$per."'> 上一页</a>";
}
if($page != $Totalpage)
{
echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$next."'> 下一页</a>";
echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$Totalpage."'> 尾页</a>";
}
$myurl=$_SERVER['PHP_SELF'].'?page';
//下拉跳转列表,循环列出所有页码:
$pagenav .= " 到第 <select name='topage' size='1' onchange='window.location=\"$myurl=\"+this.value'>\n";
for ($i = 1; $i <= $Totalpage; $i++) {
if ($i == $page)
$pagenav .= "<option value='$i' selected>$i</option>\n";
else
$pagenav .= "<option value='$i'>$i</option>\n";
}
$pagenav .= "</select> 页,共". $Totalpage ."页";
echo $pagenav;
}
else //如果$total为空则输出没有记录
{
echo "没有记录";
}
?>希望高手能给解决一下,最好能详细点,谢谢 展开
展开全部
<a href='".$_SERVER['PHP_SELF'].'?page='.$next."'> 下一页</a>这个地方已经不能这样写了,要把.$_SERVER['PHP_SELF'].替换掉
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
点击下一页的时候,url参数leibie就不见。 所以程序不会进入if (isset($_GET['leibie'])){ 这个里面。
你要加上leibie参数。
你要加上leibie参数。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用$_SERVER['PHP_SELF']试试,在不行直接用文件名试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询