Sorry fairly new to using PHP in my development, I've done this type of form before but it was more basic, I'm attempting to filter a result set called from SQL using a filter form which will be on the same page.
The first php statement is just to populate the page upon landing.
The second populates the filter list then does a check on the variable passed from the form submission, unfortunately the page when reloaded just populates with another random set of wheels, is this because I'm trying to override the original query and its the only one being executed? or have I made a syntax error in referencing the form from the php?
Been plugging away at this for a few hours now....
<?php
// Selecting items to be displayed in the mag range
$sql = "SELECT * FROM wheels WHERE rrp > 1 AND bigpic IS NOT NULL ORDER BY RAND() LIMIT 0 ,15;";
$featured = $db->query($sql);
// Getting diameter to create the filter list.
$getDiam = "SELECT DISTINCT diam FROM wheels WHERE diam > 11 ORDER BY diam";
$diamQuery = mysqli_query($db, $getDiam);
if (isset($_POST['filter'])) {
// taking the checkbox and assigning to filterDiam variable.
$filterDiam = $_POST['checkbox'];
$sql = "SELECT * FROM wheels WHERE diam LIKE '%" . $filterDiam . "%'";
}
$featured = $db->query($sql);
?>
The HTML form below
<form name="diamFilter" class="nav nav-pills nav-stacked category-menu" action="mags.php" method="POST">
<div class="form-group"></div>
<label for="diam">
<input type="checkbox" name="checkbox">All
(25)
</label>
<?php while($rowDiam=mysqli_fetch_assoc($diamQuery)) : ?>
<div class="form-group"></div>
<label for="diam">
<input type="checkbox" name="checkbox"><?= $rowDiam['diam']; ?>"
(25)
</label>
<?php endwhile; ?>
<button type="submit" name="filter" value="displayDiam" class="btn btn-default btn-sm btn-primary"><i class="fa fa-pencil"></i>Apply</button>
</form>