Can someone tell the place holder code to write when using mysql 'in' clause.This is sample code. I am using where 1=1 because there are more than one(dynamic) where conditions which I have not included in the below code.
<?php
$PDOconn = new PDO("mysql:host=localhost;dbname=jobportal","root","");
if(isset($_GET["btnSubmit"])) {
$qualifs = "";
foreach($_GET["list_qualif"] as $qualif) {
if($qualifs == ""){
$qualifs = $qualif;
} else {
$qualifs .= ",".$qualif;
}
}
$where = "1 = 1 "
if(!empty($qualifs)) {
$where = $where."AND qualification IN :qualifs";
}
$sql = "SELECT COUNT(*) FROM job_info WHERE $where ";
$stmt = $PDOconn->prepare($sql) or die($PDOconn->error);
if(!empty($qualifs)) {
$qualificationFormat = "(".$qualifs.")";
$stmt->bindParam(":qualifs",$qualificationFormat);
}
$stmt->execute();
$result = $stmt->fetch();
if($result[0] > 0) {
$sql = "SELECT * FROM job_info WHERE $where ";
$stmt = $PDOconn->prepare($sql) or die($PDOconn->error);
if(!empty($qualifs)) {
$qualificationFormat = "(".$qualifs.")";
$stmt->bindParam(":qualifs",$qualificationFormat);
}
$stmt->execute();
} else {
// if there is no matching rows do following
$msg = "No results";
}
}
?>
<?php
if(isset($result) && $result[0] > 0) {
while($row1 = $stmt->fetch()) {
?>
<div class='col-md-2'><?php echo $row1[14];?></div>
<div class='col-md-1'><?php $row1[1];?></div>
<?php
}
}
?>
<form action="" method="get">
<select name="list_qualif[]" multiple="multiple" style="width:100%;">
<option value="M.C.A.">M.C.A.</option>
<option value="B.C.A">B.C.A.</option>
</select>
<input type="submit" value="Submit" name="btnSubmit"/>
</form>