J'essaie de créer un formulaire dans lequel un utilisateur peut rechercher une base de données en utilisant plusieurs filtres. J'ai deux questions: Comment puis-je interroger la base de données avec plusieurs tableaux que chaque filtre sera stocké dans une variable en tant que tableau sur la page de résultats. La seconde est: Comment puis-je m'assurer que si l'utilisateur laisse un filtre vide, le filtre ne le fait pas dans la requête? De plus, il n'est pas nécessaire que l'utilisateur entre quelque chose dans les deux premières entrées de texte. Merci.Comment faire une requête avec plusieurs tableaux en PHP
<form action="results.php" method="post">
\t \t \t <table id="name-inputs">
\t \t \t \t <tr>
\t \t \t \t \t <td>Common Name:</td>
\t \t \t \t \t <td><input type="text" name="commonName" class="text-input" maxlength="100"></td>
\t \t \t \t </tr>
\t \t \t \t <tr>
\t \t \t \t \t <td>Latin Name:</td>
\t \t \t \t \t <td><input type="text" name="latinName" class="text-input" maxlength="100"></td>
\t \t \t \t </tr>
\t \t \t </table>
\t \t \t <div id="plantType-container">
\t \t \t \t <ul>
\t \t \t \t \t <li class="listing-heading">Plant Type</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="plantType[]" value="Perennial"> Perennial</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="plantType[]" value="Annual"> Annual</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="plantType[]" value="Tree"> Tree</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="plantType[]" value="Shrub"> Shrub</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="plantType[]" value="Herb"> Herb</li>
\t \t \t \t </ul>
\t \t \t </div>
\t \t \t <div id="lighting-container">
\t \t \t \t <ul>
\t \t \t \t \t <li class="listing-heading">Lighting</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="lighting[]" value="Sun"> Sun</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="lighting[]" value="Sun/Part-Sun"> Sun/Part-Sun</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="lighting[]" value="Part-Sun/Shade"> Part-Sun/Shade</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="lighting[]" value="Shade"> Shade</li>
\t \t \t \t </ul>
\t \t \t </div>
\t \t \t <div id="water-container">
\t \t \t \t <ul>
\t \t \t \t \t <li class="listing-heading">Water</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="water[]" value="Average"> Dry</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="water[]" value="Dry/Average"> Dry/Average</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="water[]" value="Average"> Average</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="water[]" value="Wet/Average"> Wet/Average</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="water[]" value="Wet"> Wet</li>
\t \t \t \t </ul>
\t \t \t </div>
\t \t \t <div id="foilage-container">
\t \t \t \t <ul>
\t \t \t \t \t <li class="listing-heading">Foilage</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="foilage[]" value="Decidous"> Decidous</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="foilage[]" value="Evergreen"> Evergreen</li>
\t \t \t \t </ul>
\t \t \t \t <ul>
\t \t \t \t \t <li class="listing-heading">Deer Resistant</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="deer-res[]" value="Yes"> Yes</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="deer-res[]" value="No"> No</li>
\t \t \t \t </ul>
\t \t \t </div>
\t \t \t <div id="attracts-container">
\t \t \t \t <ul>
\t \t \t \t \t <li class="listing-heading">Attracts</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="butter/birds[]" value="Butterflies"> Butterflies</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="butter/birds[]" value="Hummingbirds"> Hummingbirds</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="butter/birds[]" value="Butterflies/Hummingbirds"> Butterflies/Hummingbirds</li>
\t \t \t \t </ul>
\t \t \t </div>
\t \t \t <div id="height-container">
\t \t \t \t <ul>
\t \t \t \t \t <li class="listing-heading">Height</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="height[]" value='1-2"'> 1-2"</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="height[]" value='3-5"'> 3-5"</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="height[]" value='5-10"'> 5-10"</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="height[]" value='10-20"'> 10-20"</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="height[]" value="20'"> 20' +</li>
\t \t \t \t </ul>
\t \t \t </div>
\t \t \t <div id="color-container">
\t \t \t \t <ul>
\t \t \t \t \t <li class="listing-heading">Flower Color</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="color[]" value="White"> White</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="color[]" value="Pink"> Pink</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="color[]" value="Red"> Red</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="color[]" value="Blue"> Blue</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="color[]" value="Orange"> Orange</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="color[]" value="Yellow"> Yellow</li>
\t \t \t \t \t <li class="listing"><input type="checkbox" name="color[]" value="Purple"> Purple</li>
\t \t \t \t </ul>
\t \t \t </div>
\t \t \t <button type="submit" id="sButton">Submit</button>
\t \t </form>
<?php
\t $commonName = $_POST['commonName'];
\t $latinName = $_POST['latinName'];
\t $plantType = $_POST['plantType'];
\t $lighting = $_POST['lighting'];
\t $water = $_POST['water'];
\t $foilage = $_POST['foilage'];
\t $attracts = $_POST['attracts'];
\t $height = $_POST['height'];
\t $color = $_POST['color'];
?>
<?php
\t \t $con = new mysqli("localhost", "root", "root", "Plants");
\t \t if($con->connect_error()) {
\t \t \t echo "Connection Error: " . $con->connect_error();
\t \t } else {
\t \t \t $sql = "SELECT * FROM plants where plantType like '%$plantType%' AND lighting like '%$lighting%' AND water like '%$water%' AND foilage like '%$foilage%' AND attracts like '%$attracts%' AND height like '%$height%' AND color like '%$color%'";
\t \t \t $res=$con->query($sql);
\t \t \t echo "<table id='result-table'>";
\t \t \t while ($res = $con->fetch_assoc()) {
\t \t \t \t echo "<tr>";
\t \t \t \t echo "<td>" . $row['commonName'] . "</td>";
\t \t \t \t echo "<td>" . $row['latinName'] . "</td>";
\t \t \t \t echo "<td>" . $row['plantType'] . "</td>";
\t \t \t \t echo "<td>" . $row['lighting'] . "</td>";
\t \t \t \t echo "<td>" . $row['water'] . "</td>";
\t \t \t \t echo "<td>" . $row['foilage'] . "</td>";
\t \t \t \t echo "<td>" . $row['attracts'] . "</td>";
\t \t \t \t echo "<td>" . $row['height'] . "</td>";
\t \t \t \t echo "<td>" . $row['color'] . "</td>";
\t \t \t \t echo "</tr>";
\t \t \t }
\t \t \t echo "</table>";
\t \t }
\t ?>
Connaissez-vous que vous devez accepter les réponses? – Tobia