所以我想應用一個SQL查詢的顯示基於製造商選擇的磁盤輪的過濾器。使用PHP篩選MYSQL結果與HTML表單選項選擇器使用PHP
到目前爲止,它爲html表單生成一個下拉列表,並且應該使用$ _POST傳遞它,然後應用於sql查詢以重新顯示頁面。我有類似的工作,但使用數組和複選框,而不是此表單中使用的選項>框。
目前它不適用於任何過濾器和正式爆發產生的車輪將要顯示的環...生成的製造商列表從中選擇,並從提交後
// Getting manufacturer to create the filter list.
$filterManu = "SELECT DISTINCT manufacturer FROM wheels";
$filterManuResult = mysqli_query($db, $filterManu) or die("Error in Selecting " . mysqli_error($db));
// Applying the filtering
if (isset($_POST['manu'])) {
$option = $_POST['manu'];
$featuredsql = "SELECT * FROM wheels WHERE manufacturer = " . $option . " ORDER BY diam";
}
$featured = $db->query($featuredsql);
表形成。
<form name="manuFilter" method="POST">
<div class="form-group"></div>
<select name="manu">
<option selected disabled>Select a manufacturer</option>
<?php while($rowManu = mysqli_fetch_assoc($filterManuResult)) : ?>
<option name="manu" value="<?php echo $rowManu['manufacturer']; ?>"><?php echo $rowManu['manufacturer']; ?></option>
<?php endwhile; ?>
</select>
<div class="form-group"></div>
<button type="submit" name="filterOptions" value="displayManu" class="btn btn-default btn-sm btn-primary"><i class="fa fa-pencil"></i> Apply</button>
</form>