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

WBOY
Release: 2016-06-13 10:23:28
Original
985 people have browsed it

如何实现多个查找框内只需填写至少一个查找内容即可进行查找
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手册。
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!