php必须满足两个条件(id和title)才输出结果 5
<formaction="search.php"method="POST">部门名称:<inputtype="text"size=25name="id"value="">...
<form action="search.php" method="POST">
部门名称:<input type="text" size=25 name="id" value=""> <br><br>
员工姓名: <input type="text" size=25 name="title" value=""> <br><br>
<input type="submit" name="提交" value="提交">
</form>
<?php
//注释1-----------------------------
$id=$_POST["id"];
$title=$_POST["title"];
//注释2------------------------
if(
$id != null){
$a = " and id like '%$id%'";}
if($title != null){
$b = " and title like '%$title%'";}
//注释3------------------------
$q = "SELECT * FROM dede_archives where (1=1)";
$q .=$a;
$q .=$b;
//注释4------------------------------------------
mysql_query("SET NAMES GB2312");
$rs = mysql_query($q, $link);
echo "<table>";
echo "<tr><td>部门</td><td>员工姓名</td></tr>";
while($row = mysql_fetch_object($rs))
echo "<tr><td>$row->id</td><td>$row->title</td></tr>";
echo "</table>";
mysql_close($link);
?>
目前是任意一样满足就输出了结果 展开
部门名称:<input type="text" size=25 name="id" value=""> <br><br>
员工姓名: <input type="text" size=25 name="title" value=""> <br><br>
<input type="submit" name="提交" value="提交">
</form>
<?php
//注释1-----------------------------
$id=$_POST["id"];
$title=$_POST["title"];
//注释2------------------------
if(
$id != null){
$a = " and id like '%$id%'";}
if($title != null){
$b = " and title like '%$title%'";}
//注释3------------------------
$q = "SELECT * FROM dede_archives where (1=1)";
$q .=$a;
$q .=$b;
//注释4------------------------------------------
mysql_query("SET NAMES GB2312");
$rs = mysql_query($q, $link);
echo "<table>";
echo "<tr><td>部门</td><td>员工姓名</td></tr>";
while($row = mysql_fetch_object($rs))
echo "<tr><td>$row->id</td><td>$row->title</td></tr>";
echo "</table>";
mysql_close($link);
?>
目前是任意一样满足就输出了结果 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询