PDO returns only half the results from mysql

In the following script, I bound all the parameters using positional offsets to process the offer INin the PDO. $_POST["group"]- an array. The Chrome console shows that there are 12 values โ€‹โ€‹in the form dataset. The number of question marks in the In section also matches the meaning of the values. Everything seems to be fine.

SELECT a.id,a.likes,a.dislikes from `like_dislike` a 
INNER JOIN `model_no` b ON a.id = b.id 
WHERE b.model_no IN (?,?,?,?,?,?,?,?,?,?,?,?)

But I have no idea why the script can return only six of the results.

0 likes, 0 dislikes
0 likes, 0 dislikes
0 likes, 0 dislikes
0 likes, 0 dislikes
0 likes, 0 dislikes
0 likes, 0 dislikes

I also run the request in phpmyadmin and there are no problems with the request. Can someone see if something is wrong during the binding process?

$dbh = new PDO("mysql:host=$hostname;dbname=$databasename", $username, $password);
$id_group = $_POST["group"];
$in  = str_repeat('?,', count($id_group) - 1) . '?';    

$sql = "SELECT a.id,a.likes,a.dislikes from `like_dislike` a 
        INNER JOIN `model_no` b ON a.id = b.id WHERE b.model_no IN ($in)";

$users = $dbh->prepare($sql);
$i = 1;
foreach ($id_group as $id) {
  $users->bindValue($i++, $id);
}

$users->execute($id_group);

$rows = $users->fetchAll();


foreach($rows as $row)
{    
 echo "<div id='tid_".$row['id'].">".$row['likes']." likes, ".$row['dislikes']." dislikes</div>";      
}
+4
source share
1 answer

, ,

foreach($rows as $row)
{    
 echo "<div id='tid_".$row['id'].">".$row['likes']." likes, ".$row['dislikes']." dislikes</div>";   
               ^--this quote     ^--you forgot to end here.
}

{} / . .

 echo "<div id='tid_{$row['id']}'>{$row['likes']} likes, {$row['dislikes']} dislikes</div>";   
+2

All Articles