title: PHP json_encode returning single row only
body: <p>So I have an associative array <code>$_SESSION['cart_items'])</code>  This is the current output when I <code>print_r($_SESSION['cart_items'])</code>:</p>
  
  <pre><code>Array
  (
      [3] =&gt; 23
      [5] =&gt; 5
      [4] =&gt; 1
  )
  </code></pre>
  
  <p>In the output above, the first one for example [3]=>23 where [3] is the id and 23 is the quantity I entered from a form:</p>
  
  <p>My current data:</p>
  
  <p><a href="https://i.stack.imgur.com/ORGa9.png" rel="nofollow"><img src="https://i.stack.imgur.com/ORGa9.png" alt="enter image description here"></a></p>
  
  <p>Note that in the image above, the quantity column is different from the quantity I'm entering from a form.</p>
  
  <p>So far this is the code I've tried:</p>
  
  <pre><code>$statement = $conn-&gt;query("SELECT id, name, price, quantity FROM product WHERE id IN (".implode(',',$_SESSION['cart_items']).")");
  
  while($row = $statement-&gt;fetch(PDO::FETCH_ASSOC)) {
      $data[] = $row;
  
  }
  
  print json_encode($data);
  </code></pre>
  
  <p>And this is the output:</p>
  
  <pre><code>[{"id":"5","name":"ballpen","price":"23","quantity":"13"}]
  </code></pre>
  
  <p>As you can see it works, though I only get a single row which should be three. </p>
  
  <p>Is there something wrong with my query?</p>