So I'm trying to apply a filter for a sql query which displays the mag wheels based on the manufacturer selected.
So far it generates a dropdown list for the html form, and is supposed to pass it back using $_POST and then is applied to the sql query to redisplay the page. I have something similar working but that uses an array and checkboxs instead of the option> box used in this form.
currently It doesn't apply any filter and actually breaks the loop which generates the wheels to be displayed...
// 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 that generates the list of manufacturers to select from and submits the post from the form.
<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>