我做了一个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>';
}
}
}
?>
答案 0 :(得分:2)
更改
$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%') ";