I'm using the IN() operator to fetch multiple data from MySQL in a single query. But I'm having issues adding the results in to an array.
$sql = "SELECT employeeName, sum(emID) as count1 FROM people WHERE dept IN (:department1,:department2,:department3)";
$stmt = $connnect->prepare($sql);
$stmt->execute(array(':department1'=>"design", ':department2=>"web", ':department3=>"copywriting"));
$rslts = $stmt->fetchAll(PDO::FETCH_ASSOC);
$cont = $rslts[0]['count1']
if($cont > 0){
$myArry['em1'] = $rslts[0]["employeeName"];
$myArry['em2'] = $rslts[1]["employeeName"];
$myArry['em3'] = $rslts[2]["employeeName"];
}
EDIT:
there was a typo. I've fixed it now. if(cont > 0){
Ok i will put it here Becky
You have nothing called $connnect
Edit:
The Manual is your friend
Return Values
Returns TRUE on success or FALSE on failure.
PDOStatement::errorCode()
PDOStatement::errorInfo()
if (!$stmt->execute( [what u have] ))
throw new Exception('[' . $stmt->errorCode() . ']: ' . $stmt->errorInfo());