Maison >développement back-end >tutoriel php >求前辈帮助 php调用数据库,select where中怎么给变量加通配符%
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."%'";