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 "没有记录";
}
?>
希望高手能给说明一下,最好能详细一点啊,谢谢 展开
4个回答
展开全部
因为$_GET['leibie']未传递
......
<?
$myurl=$_SERVER['PHP_SELF'].'?leibie='.$leibie;
?>
<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='".$myurl."'>首页</a>";
echo "<a href='".$myurl.'&page='.$per."'> 上一页</a>";
}
if($page != $Totalpage)
{
echo "<a href='".$myurl.'&page='.$next."'> 下一页</a>";
echo "<a href='".$myurl.'&page='.$Totalpage."'> 尾页</a>";
}
$myurl.='&page';
//下拉跳转列表,循环列出所有页码:
$pagenav .= " 到第 <select name='topage' size='1' onchange='window.location=\"$myurl=\"+this.value'>\n";
....
......
<?
$myurl=$_SERVER['PHP_SELF'].'?leibie='.$leibie;
?>
<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='".$myurl."'>首页</a>";
echo "<a href='".$myurl.'&page='.$per."'> 上一页</a>";
}
if($page != $Totalpage)
{
echo "<a href='".$myurl.'&page='.$next."'> 下一页</a>";
echo "<a href='".$myurl.'&page='.$Totalpage."'> 尾页</a>";
}
$myurl.='&page';
//下拉跳转列表,循环列出所有页码:
$pagenav .= " 到第 <select name='topage' size='1' onchange='window.location=\"$myurl=\"+this.value'>\n";
....
展开全部
$total = mysql_fetch_array(mysql_query("select count(*) from wenzhang where leibie=".$leibie.""));
这句用到了 $leibie
但是
http://127.0.0.1/xuanchuanpian/mulu.php?page=2
没有 $leibie
不知道你要查询什么
估计你想要
是http://127.0.0.1/xuanchuanpian/mulu.php?leibie='关于我们'
点击下一页时候的地址:http://127.0.0.1/xuanchuanpian/mulu.php?page=2&leibie='关于我们'
这句用到了 $leibie
但是
http://127.0.0.1/xuanchuanpian/mulu.php?page=2
没有 $leibie
不知道你要查询什么
估计你想要
是http://127.0.0.1/xuanchuanpian/mulu.php?leibie='关于我们'
点击下一页时候的地址:http://127.0.0.1/xuanchuanpian/mulu.php?page=2&leibie='关于我们'
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
http://127.0.0.1/xuanchuanpian/mulu.php?leibie='关于我们'
点击下一页时候的地址:http://127.0.0.1/xuanchuanpian/mulu.php?page=2
没看你代码,不过URL就是错的。PHP的URL传递参数是用&隔开的
你把URL改成http://127.0.0.1/xuanchuanpian/mulu.php&page=2试试
点击下一页时候的地址:http://127.0.0.1/xuanchuanpian/mulu.php?page=2
没看你代码,不过URL就是错的。PHP的URL传递参数是用&隔开的
你把URL改成http://127.0.0.1/xuanchuanpian/mulu.php&page=2试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
"<a href='".$_SERVER['PHP_SELF'].'?page='.$per."'> 上一页</a>";
$total = mysql_fetch_array(mysql_query("select count(*) from wenzhang where leibie=".$leibie.""));
这少带了一个$leibie变量吧"<a href='".$_SERVER['PHP_SELF'].'?leibie='关于我们'
&page='.$per."'> 上一页</a>";
$total = mysql_fetch_array(mysql_query("select count(*) from wenzhang where leibie=".$leibie.""));
这少带了一个$leibie变量吧"<a href='".$_SERVER['PHP_SELF'].'?leibie='关于我们'
&page='.$per."'> 上一页</a>";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询