Hi All
First post on this forum so please be gentle!
I’d like to be able to filter a list of SQL results using php checkboxes but without having the data displayed in a table.
I’ve found (and tried) tutorials on this kind of thing but can figure out how to manipulate them to fit my needs (I’m by no means a coder, I’ve learnt as I’ve gone along but cant seem to figure this one out!)
Closest I’ve seen was by @James_Hibbard on this forum but again, it was output into a table.
I’ve got my page HERE which is a dynamically built list of food items from my database. My filter lists are also built dynamically from the options in the relevant columns in my food items table…
Filter Code Example…
<?php
$sql = "
SELECT *
FROM food_items
INNER JOIN directory
ON food_items.author = directory.author
ORDER BY directory.area
";
$result = $con->query($sql);
if ($result->num_rows > 0)
{
$areaFilter = '';
while($row = $result->fetch_assoc())
{
if($areaFilter != $row["area"])
{
$areaFilter = $row["area"];
echo '<div><input type="checkbox" id="id_' . $areaFilter . '" name="' . $areaFilter . '"><label for="AreaStalybridge">' . $areaFilter . '</label></div>';
}
}
};
?>
And here’s the code for the dynamic list of food items, grouped by course…
<?php
$sql = "
SELECT *
FROM food_items
INNER JOIN directory
ON food_items.author = directory.author
INNER JOIN courses
ON food_items.course_id = courses.course_id
ORDER BY food_items.course_id
";
$result = $con->query($sql);
if ($result->num_rows > 0)
{
$curCategory = '';
while($row = $result->fetch_assoc())
{
if($curCategory != $row["course"])
{
$curCategory = $row["course"];
echo '<p class="menuCourseHeader"><strong>' . $curCategory . '</strong></p>';
}
echo
'<div class="menuItemContainer">
<div class="menuItemContainerLeft"> <p class="menuVenue">' . $row["pub_name"] . '</p><p class="menuVenue">' . $row["area"] . '</p> </div>
<div class="menuItemContainerMain">
<p class="menuItem">' . $row["item"] . ' - £' . $row["price"] . '</p>
<p class="menuDescription">' . $row["description"] . '</p>
</div>
<div class="menuItemContainerRight"><p class="menuVenue">' . $row["course"] . '</p> </div>
</div>';
}
};
echo '<hr/>';
$con->close();
?>
If anybody can point me in the right direction, your help would be very much appreciated.
Cheers, Mark.