求前辈帮助 php调用数据库,select where中怎么给变量加通配符%
程序员文章站
2022-06-05 23:17:27
...
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 "";
}else{
echo "";
}
}
?>
$search是通过表单得到的要搜索的值,$sql是要找和$search想近的值
怎么给$search加通配符%?
$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 "";
}else{
echo "";
}
}
?>
$search是通过表单得到的要搜索的值,$sql是要找和$search想近的值
怎么给$search加通配符%?
回复讨论(解决方案)
sql怎么写怎么加
实时输出 sql看看
$sql="select * from lydata where name LIKE '%".$search."%'";