I am making a website that has jobs, and someone can filter the jobs by category. However, someone may not always filter a job, so it has to depend upon checked check-boxes on the front end. Once it gets to the PHP file, it must implode the array, then use each variable to parameterize the query. I found a few links that showed how to do a similar application, but it i couldnt find any material on how to do this with an IF statement and a prepared mysqli statement.
$o = 'o';
$sql="SELECT pid,title,description,location FROM jobs WHERE status=? ORDER BY job_date DESC";
if(isset($_POST['category'])){
$category_filter = implode("','",$_POST['category']);
$sql .= " AND category=? IN('".$category_filter."')";
}
$stmt = $conn->prepare($sql);
$stmt->bind_param('ss', $o,$category_filter);
$stmt->execute();
$stmt->bind_result($pid,$title,$description,$location);
$job = '';
while($stmt->fetch()){
include '../templates/job-listing.php';
}