title: while($row = mysql_fetch_assoc($result)) - How to foreach $row?
body: <p>I am working on a simple order system.</p>
  
  <p>the peice of code I am stuck on is the following:</p>
  
  <pre><code>if (isset($_GET['cart']))
  {
  $cart = array();
  $total = 0;
  foreach ($_SESSION['cart'] as $id)
  {
      foreach ($items as $product)
      {
          if ($product['id'] == $id)
          {
              $cart[] = $product;
              $total += $product['price'];
              break;
          }
      }
  }
  
  include 'cart.html.php';
  exit();
  }
  </code></pre>
  
  <p>This is the code is build on a preset array. I am working with a table with a few columns in mysql.</p>
  
  <p>I have decided on the following:</p>
  
  <pre><code>if (isset($_GET['cart']))
  {
  $cart = array();
  $total = 0;
  foreach ($_SESSION['cart'] as $id)
  {
              while($row = mysql_fetch_assoc($productsSql)) {
      foreach ($row as $product)
      {
          if ($product['id'] == $id)
          {
              $cart[] = $product;
              $total += $product['price'];
              break;
          }
      }
  }
      include 'cart.html.php';
  exit();
  }}
  </code></pre>
  
  <p>To display this "cart" I have decided on this:</p>
  
  <pre><code>foreach ($cart as $item) {
          $pageContent .= '
                  &lt;tr&gt;
                      &lt;td&gt;'.$item['desc'].'&lt;/td&gt;
                      &lt;td&gt;
                          R'.number_format($item['price'], 2).'
                      &lt;/td&gt;
                  &lt;/tr&gt;
  ';
  
      }
  </code></pre>
  
  <p>All this seems to do is produce my cart in a fashion where when viewed it displays a list of only the items' id, e.g. where the description and price are supposed to be, I only get the items id in both fields... I also get a total price of 0.</p>
  
  <p>Can anyone spot where I am going wrong here?</p>
  
  <p>Or atleast try to give me some input so that I get going in the right direction!</p>
  
  <p>Thanks!!</p>
  
  <pre><code>$productsQuery = 'SELECT `id`, `refCode`, `desc`, `pack`, `measure`, `quantity`, `deptCode`, `taxable`, `price1`, `price2`, `crdCode`, `cost1`, `cost2` FROM `products` ORDER BY `desc` ';
  $productsSql = mysql_query($productsQuery) or die(mysql_error());
  if (mysql_num_rows($productsSql) == 0) {
  die('No results.');
  } else {
  $orderContent = '';
  while($row = mysql_fetch_assoc($productsSql)) {
  $prId = $row['id'];
  $prRefCode = $row['refCode'];
  $prDesc = $row['desc'];
  $prPack = $row['pack'];
  $prMeasure = $row['measure'];
  $prQuantity = $row['quantity'];
  $prDeptCode = $row['deptCode'];
  $prTaxable = $row['taxable'];
  $prPrice1 = $row['price1'];
  $prPrice2 = $row['price2'];
  $prCrdCode = $row['crdCode'];
  $prCost1 = $row['cost1'];
  $prCost2 = $row['cost2'];
  $orderContent .= '
      &lt;tr&gt;
          &lt;td&gt;'.$prId.'&lt;/td&gt;
          &lt;td&gt;'.$prDesc.'&lt;/td&gt;
          &lt;td&gt;'.$prPack.'x'.$prSize.' '.$prMeasure.'&lt;/td&gt;
          &lt;td&gt;R'.$prPrice1.'&lt;/td&gt;
          &lt;td&gt;
              &lt;form action="" method="post"&gt;
                  &lt;div&gt;
                      &lt;input type="text" size="3" name="quantity" /&gt; 
                  &lt;/div&gt;
              &lt;/form&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;form action="" method="post"&gt;
                  &lt;div&gt;
                      &lt;input type="hidden" name="id" value="'.$prId.'" /&gt;
                      &lt;input type="submit" name="action" value="Order" /&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
          &lt;/td&gt;           
     &lt;/tr&gt;
  ';
  }}
  </code></pre>