我正在使用复选框过滤来自数据库的结果,并且它可以与一个复选框一起正常工作,但是当我选中多个复选框时,它仅返回第一个复选框的行。我怎样才能让它用多个复选框过滤结果?
这是复选框
<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>
这是选择查询。第三else if
条语句仅返回第一个复选框值,即篮球
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);
}