读书人

php分页输出有关问题

发布时间: 2013-06-19 10:26:41 作者: rapoo

php分页输出问题



<form method="post" name="form" id="form" ction="index.php?act=query" onSubmit="return chkinput_search(this)">

<input id="search" type="text" name="search" size="60" value="" placeholder="请输入搜索"/><select name="xuanze"id="xuanze" >

<option selected value="shoptype">类型</option>
<option value="user">账号</option>
<option value="shopname">店名</option>
</select>
<input class="submit"name="submit" type="submit" value="查询" />
</form>这里是 search.php页的
*****************************
这里是searchshow.php 页的
<?php session_start();
?>
<meta charset="utf-8">
<?php
include("conn/conn.php");
include("search.php");

$search=$_POST[search];
$xuanze=$_POST[xuanze];
if($_POST[search]==""){
$search=$_GET[search];
$xuanze=$_GET[xuanze];
}

if(shoptype=="$xuanze"){
$sql1=mysql_query("select count(*) as total from tb_members where shoptype='$search' order by mid");
}elseif(user=="$xuanze"){
$sql1=mysql_query("select count(*) as total from tb_members where user='$search' order by mid");
}elseif(shopname=="$xuanze"){
$sql1=mysql_query("select count(*) as total from tb_members where shopname='$search' order by mid");
}



$minfo=mysql_fetch_array($sql1);//在这里出错
$total=$minfo[total];
$pagesize=5;
if($total<=$pagesize){
$pagecount=1;
}
if(($total%$pagesize)!=0){
$pagecount=intval($total/$pagesize)+1;
}else{
$pagecount=$total/$pagesize;
}
if(($_GET)==""){
$page=1;
}else{
$page=intval($_GET);
}


if(shoptype=="$xuanze"){
$sql=mysql_query("select * from tb_members where shoptype='$search' order by mid limit ".($page-1)*$pagesize.",$pagesize");
}elseif(user=="$xuanze"){
$sql=mysql_query("select * from tb_members where user='$search' order by mid limit ".($page-1)*$pagesize.",$pagesize");
}
elseif(shopname=="$xuanze"){
$sql=mysql_query("select * from tb_members where shopname='$search' order by mid limit ".($page-1)*$pagesize.",$pagesize");
}



$info=mysql_fetch_array($sql);//在这里也出错
?><table class="jieguo"width="100%" border="1" cellspacing="1" cellpadding="2">
<tr style=" background:url(images/nav_03.jpg)">

<td height="25px;" width="100">帐号</td>
<td width="100">联系人</td>
<td width="200">店铺名称</td>
<td width="60">类型</td>
<td width="120">联系电话</td>
<td width="240">联系地址</td>
</tr>
<?php
if($info){
do{ ?>
<tr>

<td height="70px;" ><?php echo $info['user'];?></td>
<td><?php echo $info['zhenming'];?></td>


<td><?php echo $info['shopname'];?></td>
<td><?php echo $info['shoptype'];?></td>
<td><?php echo $info['tel'];?></td>
<td><?php echo $info['address'];?></td>

</tr>
<?php
}while($info=mysql_fetch_array($sql));
?>
</table>
  共有 
<?php
echo $total;
?>
 条 每页显示 <?php echo $pagesize;?> 条 第 <?php echo $page;?> 页/共 <?php echo $pagecount; ?> 页
<?php
if($page>=2){
?>
<a href="index.php?xuanze=<?php echo $xuanze;?>&search=<?php echo $search;?>&page=1" title="首页"></a>
<a href="index.php?xuanze=<?php echo $xuanze;?>&search=<?php echo $search;?>&page=<?php echo $page-1;?>" title="上一页"></a>
<?php
}
if($pagecount<=4){
for($i=1;$i<=$pagecount;$i++){
?>
<a href="index.php?xuanze=<?php echo $xuanze;?>&search=<?php echo $search;?>&page=<?php echo $i;?>"><?php echo $i;?></a>
<?php
}
}else{
for($i=1;$i<=4;$i++){
?>
<a href="rrrr.php?xuanze=<?php echo $xuanze;?>&search=<?php echo $search;?>&page=<?php echo $i;?>"><?php echo $i;?></a>
<?php }?>
<a href="index.php?xuanze=<?php echo $xuanze;?>&search=<?php echo $search;?>&page=<?php echo $page-1;?>" title="下一页"></a>
<a href="index.php?xuanze=<?php echo $xuanze;?>&search=<?php echo $search;?>&page=<?php echo $pagecount;?>" title="尾页"></a>
<?php }?>

<?php
}else{
?>
对不起,您检索的信息不存在!
<?php
}mysql_close();

?>


这是出错的地方
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\AppServ\www\shihui\admin\searchshow.php on line 33

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\AppServ\www\shihui\admin\searchshow.php on line 70


[解决办法]
把sql输出来。
[解决办法]
说明你的查询失败了,返回的查询结果有问题,打印查询语句分析一下吧
[解决办法]
}

if(shoptype=="$xuanze"){
$sql1=mysql_query("select count(*) as total from tb_members where shoptype='$search' order by mid");
}elseif(user=="$xuanze"){
$sql1=mysql_query("select count(*) as total from tb_members where user='$search' order by mid");
}elseif(shopname=="$xuanze"){
$sql1=mysql_query("select count(*) as total from tb_members where shopname='$search' order by mid");
}
条件出错了,$sql为空,正确如
if($search=="shopname")

读书人网 >PHP

热点推荐