mardi 17 mai 2016

How to select data out the database when the string contains the value in the database?

enter image description here

Here is my code:

        if (isset($_POST['zoek']))
        {       
            // Create connection
            $conn = new mysqli($servername, $username, $password, $dbname);
            // Check connection
            if ($conn->connect_error) {
                die("Connection failed: " . $conn->connect_error);
            } 

                if (isset($_POST['ingredienten']) && !empty($_POST['ingredienten'])) 
                {
                    echo $fruitList = implode(',', $_POST['ingredienten']);
                }


                $sql = "SELECT * FROM keuzes, keuzes2, keuzes3, keuzes4, register, gerechten WHERE gerechten.ingredienten1 IN ($fruitList) AND gerechten.ingredienten1 = keuzes.ID AND gerechten.tijdsduren = keuzes2.ID AND gerechten.ratings = keuzes3.ID AND gerechten.maaltijden1 = keuzes4.ID AND gerechten.IDpersoon = register.ID";

                $result = $conn->query($sql);

                if ($result->num_rows > 0) {
                    // output data of each row
                    while($row = $result->fetch_assoc()) {

                        }
                    } else {

                    }
                    $conn->close();
        }

This is the fruitList. These are all ingrediënts from the table: 'keuzes'.

        $selectAllPostsQuery = "SELECT * FROM keuzes";
        $resource = $conn->query($selectAllPostsQuery);
        /* When there's connection it will post the database information */
        if ($resource)
            {
                    while ($data = $resource->fetch_assoc())
                {
                    ?> 
                    <div style="padding: 2px; margin-left: 25px"><input type="checkbox" name="ingredienten[]" value="<?php echo $data['ID'] ?>"><?php echo $data['ingredienten'] ?><br></div>

I want to drop date out the database when I selected all the values from a column in the database (look above for the database image). But I get the data even when I choose the first value.




Aucun commentaire:

Enregistrer un commentaire