title: displaying all items in session array. only the top item is showing
body: <p><code>$_SESSION['cart']</code> is stored in an array, and I used <code>foreach</code> to get all the product id in <code>$_SESSION['cart']</code> to be used in my query. however, only the top of <code>$_SESSION['cart']</code> array is displayed and I can't find a way to display all products stored in the session. Every time I remove the top item from the array, the next item is displayed.</p>
  
  <p>here is the code:</p>
  
  <pre><code>&lt;?php
  $action = isset($_GET['action']) ? $_GET['action'] : "";
  
  if ($action == 'removed') {
      echo "&lt;div&gt;" . $_GET['name'] . " was removed from cart.&lt;/div&gt;";
  }
  
  if (isset($_SESSION['cart'])) {
      $ids = "";
      foreach ($_SESSION['cart'] as $id) {
          $ids = $ids . $id . ",";
      }
  
      //remove the last comma
      $ids = rtrim($ids, ',');
  
      $query = "SELECT productID, productName, productPrice FROM tblproducts WHERE productID='$ids' ";
      $result = mysql_query($query);
      $num_rows = mysql_num_rows($result);
  
      if ($num_rows &gt; 0) {
          echo "&lt;table border='0'&gt;"; //start table
  
          // our table heading
          echo "&lt;tr&gt;";
          echo "&lt;th class='textAlignLeft'&gt;Product Name&lt;/th&gt;";
          echo "&lt;th&gt;Price (PHP)&lt;/th&gt;";
          echo "&lt;th&gt;Action&lt;/th&gt;";
          echo "&lt;/tr&gt;";
  
          //also compute for total price
          $totalPrice = 0;
  
          while ($row = mysql_fetch_array($result)) {
  
              $totalPrice += $row['productPrice'];
  
              //creating new table row per record
              echo "&lt;tr&gt;";
              echo "&lt;td&gt;" . $row['productName'] . "&lt;/td&gt;";
              echo "&lt;td class='textAlignRight'&gt;" . $row['productPrice'] . "&lt;/td&gt;";
              echo "&lt;td class='textAlignCenter'&gt;";
              echo "&lt;a href='remove-from-cart.php?id=" . $row['productID'] . "&amp;name=" . $row['productName']
                  . "'\" class='custom-button'&gt;";
              echo "&lt;img src='../../images/front/removefromcart.png' title='Remove from cart' width='80' height='50' /&gt;";
              echo "&lt;/a&gt;";
              echo "&lt;/td&gt;";
              echo "&lt;/tr&gt;";
          }
  
          echo "&lt;tr&gt;";
          echo "&lt;th class='textAlignCenter'&gt;Total Price&lt;/th&gt;";
          echo "&lt;th class='textAlignRight'&gt;{$totalPrice}&lt;/th&gt;";
          echo "&lt;th&gt;&lt;/th&gt;";
          echo "&lt;/tr&gt;";
  
          echo "&lt;/table&gt;";
          echo "&lt;br /&gt;&lt;div&gt;&lt;a href='#' class='customButton'&gt;Checkout&lt;/a&gt;&lt;/div&gt;";
      } else {
          echo "&lt;div&gt;No products found in your cart. :(&lt;/div&gt;";
      }
  } else {
      echo "&lt;div&gt;No products in cart yet.&lt;/div&gt;";
  }
  
  ?&gt;
  </code></pre>