I am filtering the results from the database using checkboxes and it works fine with one checkbox however when I check multiple checkboxes it returns the rows only for the first checkbox. How can I have it to filter the results with multiple checkboxes?
Here are the checkboxes
<form id="form" method="post" action="">
<input type="checkbox" name="football" class="checkbox" <?=(isset($_POST['football'])?' checked':'')?>/> Football<br>
<input type="checkbox" name="basketball" class="checkbox" <?=(isset($_POST['basketball'])?' checked':'')?>/> Basketball<br>
<input type="checkbox" name="volleyball" class="checkbox" <?=(isset($_POST['volleyball'])?' checked':'')?>/> Volley Ball<br>
</form>
<script type="text/javascript">
$(function(){
$('.checkbox').on('change',function(){
$('#form').submit();
});
});
</script>
here is the select query.. the third else if statement returns only the first checkbox value which is basketball
if (isset($_POST["football"])){
$paginate = new pagination($page, "SELECT * FROM balls where type LIKE '%foot%' ORDER BY id desc", $options);
}
else if (isset($_POST["basketball"])){
$paginate = new pagination($page, "SELECT * FROM balls where type LIKE '%bask%' ORDER BY id desc", $options);
}
else if (isset($_POST["volleyball"])){
$paginate = new pagination($page, "SELECT * FROM balls where type LIKE '%vol%' ORDER BY id desc", $options);
}
else if (isset($_POST["basketball"]) && isset($_POST["football"]) && isset($_POST["volleyball"])){
$paginate = new pagination($page, "SELECT * FROM balls where type LIKE '%bask%' or type LIKE '%foot%' or type LIKE '%vol%' ORDER BY id desc", $options);
}
else { $paginate = new pagination($page, 'SELECT * FROM balls ORDER BY id desc', $options);
}