![](/img/trans.png)
[英]PDOStatement::execute Values doesn't work with WHERE Condition & HAVING Condition
[英]where condition doesn't work
我已经做了一个具有很多复选框的html设计,我想获取此复选框的值并在数据库中搜索与此相似的数据,问题出在查询中……虽然我已经测试过,但条件不起作用在phpmyadmin中,它是可行的。
<?php
$conn = mysqli_connect("localhost","root","","bella_vista");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if (isset($_POST['submit'])) {
foreach ($_POST['Ingredient'] as $selected)
{
//sql query to search db
$query ="select name,image
from reciepe
where R_ID =any(select I_ID FROM ingredient where item like '%$selected%') ";
$result =mysqli_query ($conn,$query);
print_r ($result);
while($row = mysqli_fetch_assoc($result)) {
$name = $row['name'];
$image = $row['image'];
echo '<div>'.$name. ''.$image.'</div>';
}
}
}
?>
更改
$query ="select name,image
from reciepe
where R_ID =any(select I_ID FROM ingredient where item like '%$selected%') ";
至
$query ="SELCT name,image
FROM reciepe
WHERE R_ID IN (SELCT I_ID FROM ingredient WHERE item LIKE '%$selected%') ";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.