简体   繁体   English

条件不起作用的地方

[英]where condition doesn't work

I've made an html design that have many checkbox and I want to take values of this checkbox and search for data similar for it in the database the problem is in the query ...where condition isn't work although I've tested it in phpmyadmin and it was 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>';
     }
     }
    }
?>

Change 更改

$query ="select name,image
        from reciepe
        where R_ID =any(select I_ID FROM ingredient where item like '%$selected%') ";

To

$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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM