首页上一页 1 下一页尾页 2 条记录 1/1页
PHP分页问题
发表在PHP图书答疑
2010-04-19
是否精华
是
否
版块置顶:
是
否
这是代码
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="CADDE4">
<tr>
<td bgcolor="#FFFFFF"><table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
<?php
$type=$_GET['type'];
$area=$_GET['area'];
$oneid=$_GET['type_one'];
$twoid=$_GET['type_two'];
include('Include_Conn/Conn.php');
$sql=$db->query("select * from tb_info where type='$type' and area='$area' and type_one='$oneid' and type_two='$twoid' ");
$rs=$db->fetch_array($sql);
echo $rs['type'];
echo $rs['area'];
echo $rs['oneid'];
echo $rs['twoid'];
include('Include_Conn/Conn.php');
if($area=='所有区域'){
$sql=$db->query("select count(*) as total from tb_info where type='$type' and type_one='$oneid' and type_two='$twoid' order by addtime desc ",$conn);
$rs=$db->fetch_array($sql);
$total=$rs[total];
if(!isset($_GET["page"]) || !is_numeric($_GET["page"])){
$page=1;
}else{
$page=intval($_GET["page"]);
}
$pagesize=2;
if($total%$pagesize==0){
$pagecount=intval($total/$pagesize);
}else{
$pagecount=ceil($total/$pagesize);
}
}
if($area!='所有区域'){
$sql=$db->query("select count(*) as total from tb_info where type='$type' and area='$area' and type_one='$oneid' and type_two='$twoid' order by addtime desc ",$conn);
$rs=$db->fetch_array($sql);
$total=$rs[total];
if(!isset($_GET["page"]) || !is_numeric($_GET["page"])){
$page=1;
}else{
$page=intval($_GET["page"]);
}
$pagesize=2;
if($total%$pagesize==0){
$pagecount=intval($total/$pagesize);
}else{
$pagecount=ceil($total/$pagesize);
}
}
if($area=='所有区域'){
$sql=$db->query("select * from tb_info where type='$type' and type_one='$oneid' and type_two='$twoid' order by addtime desc limit ".($page-1)*$pagesize.",$pagesize ",$conn);
}
elseif($area!='所有区域'){
$sql=$db->query("select * from tb_info where type='$type' and area='$area' and type_one='$oneid' and type_two='$twoid' order by addtime desc limit ".($page-1)*$pagesize.",$pagesize ",$conn);
}
$info=$db->fetch_array($sql);
if($info==false){
echo "没有相关信息";
exit;
}else{
do{
?>
<tr bgcolor="#99CCFF" onmouseover='this.bgColor="#799AE1"' onmouseout='this.bgColor="#f0f0f0"'>
<td width="13%" align="center" ><img src="images/do.jpg" width="10" height="10" hspace="8" />标题:</td>
<td height="24" colspan="2" ><font size="3px" color="<?=$info[color]?>">
<?=$info[title]?>
</font></td>
</tr>
<tr>
<td align="center">发布时间:</td>
<td height="24" colspan="2"><?=$info[addtime]?>
查看次数:</td>
</tr>
<tr>
<td height="1" colspan="3" ><hr size="1" color="#CCCCCC" /></td>
</tr>
<tr>
<td align="center">信息内容:</td>
<td height="24" colspan="2"><?=$info[content]?></td>
</tr>
<tr>
<td colspan="3" background="images/line.gif" height="1"></td>
</tr>
<?php
}
while($info=$db->fetch_array($sql));
}
?>
</table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="13%" align="center">联系人: </td>
<td width="7%"><?=$info[realname]?></td>
<td width="12%" align="center"> 电话:</td>
<td width="68%"><?=$info[phone]?></td>
</tr>
</table>
<div style="height:10px"></div>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="25" align="center"> 共有记录 <?php echo $total;?> 条 每页显示 <?php echo $pagesize;?> 条 第 <?php echo $page;?> 页/共 <?php echo $pagecount;?> 页 <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=1&type=<?php echo $type;?>&area=<?php echo $area;?>&oneid=<? echo $oneid;?>&twoid=<?php echo $twoid;?>" class="a1">首页</a> <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=<?php
if($page>1)
echo $page-1;
else
echo 1;
?>&type=<?php echo $type;?>&area=<?php echo $area;?>&oneid=<?php echo $oneid;?>&twoid=<?php echo $twoid;?>" class="a1">上一页</a> <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=<?php
if($page<$pagecount)
echo $page+1;
else
echo $pagecount;
?>&type=<?php echo $type;?>&area=<?php echo $area;?>&oneid=<? echo $oneid;?>&twoid=<?php echo $twoid;?>" class="a1">下一页</a> <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=<?php echo $pagecount;?>&type=<?php echo $type;?>&area=<?php echo $area;?>&oneid=<? echo $oneid;?>&twoid=<?php echo $twoid;?>" class="a1">尾页</a> </td>
</tr>
</table>
</td>
</tr>
</table>
问题所在处:
我把下面的 type_one='$oneid' and type_two='$twoid' 改成 type_one='1' and type_two='1'
就能分页了 就是获取不到$oneid $twoid 改怎么办呢? 就是分页不成功
if($area=='所有区域'){
$sql=$db->query("select * from tb_info where type='$type' and type_one='$oneid' and type_two='$twoid' order by addtime desc limit ".($page-1)*$pagesize.",$pagesize ",$conn);
}
elseif($area!='所有区域'){
$sql=$db->query("select * from tb_info where type='$type' and area='$area' and type_one='$oneid' and type_two='$twoid' order by addtime desc limit ".($page-1)*$pagesize.",$pagesize ",$conn);
}
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="CADDE4">
<tr>
<td bgcolor="#FFFFFF"><table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
<?php
$type=$_GET['type'];
$area=$_GET['area'];
$oneid=$_GET['type_one'];
$twoid=$_GET['type_two'];
include('Include_Conn/Conn.php');
$sql=$db->query("select * from tb_info where type='$type' and area='$area' and type_one='$oneid' and type_two='$twoid' ");
$rs=$db->fetch_array($sql);
echo $rs['type'];
echo $rs['area'];
echo $rs['oneid'];
echo $rs['twoid'];
include('Include_Conn/Conn.php');
if($area=='所有区域'){
$sql=$db->query("select count(*) as total from tb_info where type='$type' and type_one='$oneid' and type_two='$twoid' order by addtime desc ",$conn);
$rs=$db->fetch_array($sql);
$total=$rs[total];
if(!isset($_GET["page"]) || !is_numeric($_GET["page"])){
$page=1;
}else{
$page=intval($_GET["page"]);
}
$pagesize=2;
if($total%$pagesize==0){
$pagecount=intval($total/$pagesize);
}else{
$pagecount=ceil($total/$pagesize);
}
}
if($area!='所有区域'){
$sql=$db->query("select count(*) as total from tb_info where type='$type' and area='$area' and type_one='$oneid' and type_two='$twoid' order by addtime desc ",$conn);
$rs=$db->fetch_array($sql);
$total=$rs[total];
if(!isset($_GET["page"]) || !is_numeric($_GET["page"])){
$page=1;
}else{
$page=intval($_GET["page"]);
}
$pagesize=2;
if($total%$pagesize==0){
$pagecount=intval($total/$pagesize);
}else{
$pagecount=ceil($total/$pagesize);
}
}
if($area=='所有区域'){
$sql=$db->query("select * from tb_info where type='$type' and type_one='$oneid' and type_two='$twoid' order by addtime desc limit ".($page-1)*$pagesize.",$pagesize ",$conn);
}
elseif($area!='所有区域'){
$sql=$db->query("select * from tb_info where type='$type' and area='$area' and type_one='$oneid' and type_two='$twoid' order by addtime desc limit ".($page-1)*$pagesize.",$pagesize ",$conn);
}
$info=$db->fetch_array($sql);
if($info==false){
echo "没有相关信息";
exit;
}else{
do{
?>
<tr bgcolor="#99CCFF" onmouseover='this.bgColor="#799AE1"' onmouseout='this.bgColor="#f0f0f0"'>
<td width="13%" align="center" ><img src="images/do.jpg" width="10" height="10" hspace="8" />标题:</td>
<td height="24" colspan="2" ><font size="3px" color="<?=$info[color]?>">
<?=$info[title]?>
</font></td>
</tr>
<tr>
<td align="center">发布时间:</td>
<td height="24" colspan="2"><?=$info[addtime]?>
查看次数:</td>
</tr>
<tr>
<td height="1" colspan="3" ><hr size="1" color="#CCCCCC" /></td>
</tr>
<tr>
<td align="center">信息内容:</td>
<td height="24" colspan="2"><?=$info[content]?></td>
</tr>
<tr>
<td colspan="3" background="images/line.gif" height="1"></td>
</tr>
<?php
}
while($info=$db->fetch_array($sql));
}
?>
</table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="13%" align="center">联系人: </td>
<td width="7%"><?=$info[realname]?></td>
<td width="12%" align="center"> 电话:</td>
<td width="68%"><?=$info[phone]?></td>
</tr>
</table>
<div style="height:10px"></div>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="25" align="center"> 共有记录 <?php echo $total;?> 条 每页显示 <?php echo $pagesize;?> 条 第 <?php echo $page;?> 页/共 <?php echo $pagecount;?> 页 <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=1&type=<?php echo $type;?>&area=<?php echo $area;?>&oneid=<? echo $oneid;?>&twoid=<?php echo $twoid;?>" class="a1">首页</a> <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=<?php
if($page>1)
echo $page-1;
else
echo 1;
?>&type=<?php echo $type;?>&area=<?php echo $area;?>&oneid=<?php echo $oneid;?>&twoid=<?php echo $twoid;?>" class="a1">上一页</a> <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=<?php
if($page<$pagecount)
echo $page+1;
else
echo $pagecount;
?>&type=<?php echo $type;?>&area=<?php echo $area;?>&oneid=<? echo $oneid;?>&twoid=<?php echo $twoid;?>" class="a1">下一页</a> <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=<?php echo $pagecount;?>&type=<?php echo $type;?>&area=<?php echo $area;?>&oneid=<? echo $oneid;?>&twoid=<?php echo $twoid;?>" class="a1">尾页</a> </td>
</tr>
</table>
</td>
</tr>
</table>
问题所在处:
我把下面的 type_one='$oneid' and type_two='$twoid' 改成 type_one='1' and type_two='1'
就能分页了 就是获取不到$oneid $twoid 改怎么办呢? 就是分页不成功
if($area=='所有区域'){
$sql=$db->query("select * from tb_info where type='$type' and type_one='$oneid' and type_two='$twoid' order by addtime desc limit ".($page-1)*$pagesize.",$pagesize ",$conn);
}
elseif($area!='所有区域'){
$sql=$db->query("select * from tb_info where type='$type' and area='$area' and type_one='$oneid' and type_two='$twoid' order by addtime desc limit ".($page-1)*$pagesize.",$pagesize ",$conn);
}