Home > Backend Development > PHP Tutorial > 求前辈帮助 php调用数据库,select where中怎么给变量加通配符%

求前辈帮助 php调用数据库,select where中怎么给变量加通配符%

WBOY
Release: 2016-06-20 12:31:08
Original
921 people have browsed it

     
               if($_POST["ok"]){
  $search=$_POST["search"];
       $sql="select * from lydata where name LIKE  '".$search."'";
  $query=mysql_query($sql) or die("链接失败");
      $num=mysql_num_rows($query);
  if ($num==0){    
  echo "<script> alert('没有资源');location.href='javascript:history.go(-1)';</script>";
  
  }else{
  
  echo "<script> alert('测试');location.href='javascript:history.go(-1)';</script>";
  }
 
 }
 
 ?>

$search是通过表单得到的要搜索的值,$sql是要找和$search想近的值

怎么给$search加通配符%?


回复讨论(解决方案)

sql怎么写怎么加
实时输出 sql看看

$sql="select * from lydata where name LIKE  '%".$search."%'";

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