循环通过会话数组来创建购物车

I am adding the id of my product to a session array when the add to cart button is clicked. How to I set up my query to loop through all of the id values in my array. At the moment I have just added my session variable into the query but obviously this isn't going to work.

Code:

  $_SESSION['cart'] = array();

  array_push($_SESSION['cart'], $_GET['theid']);


  $query = "Select * From Products WHERE ProdID = '$_SESSION['cart']'";

First of all I think you need to use an IN operator in your SQL query :

`SELECT * FROM Products WHERE ProdID IN (1,2,42, etc ...)`

As you can push IDs in your array and your query will always work.

Then use implode func to get your array as a single string to format in your sql query : http://php.net/manual/fr/function.implode.php

      $str =  implode(',', $_SESSION['cart']) ;
      $query = "SELECT * FROM Products WHERE ProdID = '$str'" ;