PHP查询问题
<?php
$wherelist=array();
if(!empty($_GET['sid']))
{
$wherelist[]=" sid like '%".$_GET['sid']."%'";
}
if(!empty($_GET['sname']))
{
$wherelist[]=" sname like '%".$_GET['sname']."%'";
}if(!empty($_GET['ssex']))
{
$wherelist[]=" ssex like '%".$_GET['ssex']."%'";
}
$where="";
if(count($wherelist)>0)
{
$where=" where ".implode(' and ',$wherelist);//implode 把数组元素组合为字符串
}
//分页的实现原理
//1.获取数据表中总记录数
$sql="select * from student $where ";
$result=mysql_query($sql);
$totalnum=mysql_num_rows($result);
//每页显示条数
$pagesize=8;
//总共有几页
$maxpage=ceil($totalnum/$pagesize);
$page=isset($_GET['page'])?$_GET['page']:1;//isset函数是检测变量是否设置。
if($page <1)
{
$page=1;
}
if($page>$maxpage)
{
$page=$maxpage;
}
$limit=" limit ".($page-1)*$pagesize.",$pagesize";//显示当前页
$sql0="select yhouse from yuangong where yid='{$_COOKIE['a']}'";
$rs0=mysql_query($sql0,$link);
$row0=mysql_fetch_assoc($rs0);
$yh=$row0['yhouse'];
$sql1="select * from student $where order by sid desc $limit"; //此处加了id降序
$res=mysql_query($sql1);
?>
为甚么我$sql1="select * from student where $yh=shourse $where order by sid desc $limit"; 变成这样搜索功能就不行了呢?求帮忙谢谢你们!