简体   繁体   中英

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.

 <?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%') ";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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