Home  >  Article  >  Backend Development  >  怎么实现多个查找框内只需填写至少一个查找内容即可进行查找

怎么实现多个查找框内只需填写至少一个查找内容即可进行查找

WBOY
WBOYOriginal
2016-06-13 10:23:28943browse

如何实现多个查找框内只需填写至少一个查找内容即可进行查找
apply.html


  A new Application for a classroom



 

CRMS - New classroom Entry



 

 
 
 
 
 
 
 
 
 
 
 
 
 
Classroom ID
Course ID

 




2.php



  A new Application for a classroom


CRMS - New classroom Entry Results


  // create short variable names
  $Cno=$_POST['Cno'];
  $CID=$_POST['CID'];

  if (!$Cno) {$Cno = "%";}
  if (!$CID) {$CID = "%";}

  if (!get_magic_quotes_gpc()) {
  $Cno = addslashes($Cno);
  $CID = addslashes($CID);
  }

$con = mysql_connect("localhost","root","");
//通过服务器locahost建立连接,用户名为root,无密码

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("crms", $con);

$search_classroom = "SELECT * FROM use2 
  WHERE Cno LIKE '{$Cno}' AND CID LIKE $CID";
$result = mysql_query($search_classroom, $con);

while($row = mysql_fetch_array($result))
  {
  echo $row['Cno'];
  echo $row['CID'];
  echo "
";
  }
mysql_close($con)
?>



为什么这样不能实现当Classroom ID 或者Course ID没有填写时,任然能够成功搜索。我已经写了 if (!$Cno) {$Cno = "%";}
  if (!$CID) {$CID = "%";}如果没有填就用通配符,而且查询时也用了LIKE(如果查询时LIKE全部换为=则成功)。为什么?在线等!

------解决方案--------------------
因为你用like了。去查下mysql手册。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn