hi guys,

since 2 days i've not been to resolve this, your help will save me further days of torture.

The below code shows the cart of a customerís session: it shows each product, quantity and price and then saveís it to a session. It all works fine.

The first problem starts when the product is a shoe. So if the product is a shoe I allow them to enter the shoe size, next to the quantity. I tried many using a foreach loop within another, but thatís just not working.

The second problem is saving the shoe size for each product the session too.

dug

output_cart.php
PHP Code:
function display_cart($cart$change true$images 1)
{
  
// display items in shopping cart
  // optionally allow changes (true or false)
  // optionally include images (1 - yes, 0 - no)

  
global $HTTP_SESSION_VARS;

  echo 
'<table border = 0 width = 100% cellspacing = 0>
        <form action = show_cart.php method = post>
        <tr>
        <th colspan = '
. (1+$images) .' bgcolor="#cccccc">Item</th>
        <th bgcolor="#cccccc">Price</th>
        <th bgcolor="#cccccc" align="left">Quantity</th>
        <th bgcolor="#cccccc" align="left">Shoesize</th>'
;
        
      echo
'  <th bgcolor="#cccccc">Total</th></tr>';

  
//display each item as a table row
  
foreach ($cart as $prdnumber => $qty)
  {
       foreach (
$cart as $prdnumber => $shoesize)
  {
    
$products get_book_details($prdnumber);
    echo 
'<tr>';
    if(
$images ==true)
    {
      echo 
'<td align = left width=5%>';
      if (
file_exists("images/$prdnumber.jpg"))
      {
         
$size GetImageSize('images/'.$prdnumber.'.jpg');  
         if(
$size[0]>&& $size[1]>0)
         {
           echo 
'<img src="images/'.$prdnumber.'.jpg" border=0 ';
           echo 
'width = '$size[0]/.' height = ' .$size[1]/'>';
         }
      }
      else
         echo 
' ';
      echo 
'</td>';
    }
        
    echo 
'<td align = left>'.$products['title'].'</a></td>';
    
    
    echo 
'<td align = left>£'.number_format($products['price'], 2).'</td>';
    
   
    echo 
'<td align = left>';
    
// if we allow changes, quantities are in text boxes
    
if ($change == true)
     echo 
"<input type = text name = \"$prdnumber\" value = \"$qty\" size = 3 align = left>";
    else
      echo 
$qty.'</td>';
      

      
      echo 
'<td align = left>';
    
// if we allow changes, quantities are in text boxes
    
if ($change == true)
     echo 
"<input type = text name = \"$prdnumber\" value = \"$shoesize\" size = 3 align = left>";
    else
      echo 
$qty.'</td>';
    
           
          
    echo 
'<td align = left>£'.number_format($products['price']*$qty,2)."</td></tr>\n";
  }
  
// display total row
  
echo '<tr>
          <th colspan = '
. (2+$images) .' bgcolor=#cccccc>
          <th align = left bgcolor=cccccc> '
;
            echo  
$HTTP_SESSION_VARS['items'];
         echo
' </th>';
         
        echo
'<th align = left bgcolor=cccccc> ';
            echo  
$HTTP_SESSION_VARS['shoesize'];
         echo
' </th>';
          
          echo
'<th align = left bgcolor=#cccccc>
              £'
; echo number_format($HTTP_SESSION_VARS['total_price'], 2);
          echo
'</th>
        </tr>'
;
  
// display save change button
  
if($change == true)
  {
    echo 
'<tr>
            <td colspan = '
. (2+$images) .'> </td>
            <td align = center>
              <input type = hidden name = save value = true>  
              <input type = image src = "images/save-changes.gif" 
                     border = 0 alt = "Save Changes">
            </td>
            <td> </td>
        </tr>'
;
  }
  echo 
'</form></table>';
}

show_cart.php
PHP Code:
 $new $HTTP_GET_VARS['new'];

  if(
$new)
  {
    
//new item selected
    
if(!isset($HTTP_SESSION_VARS['cart']))
    {
      
$HTTP_SESSION_VARS['cart'] = array();
      
$HTTP_SESSION_VARS['items'] = 0;
      
$HTTP_SESSION_VARS['shoesize'] = 0;
      
$HTTP_SESSION_VARS['total_price'] ='0.00';
      
          }
    if(isset(
$HTTP_SESSION_VARS['cart'][$new]))
      
$HTTP_SESSION_VARS['cart'][$new]++;
    else 
      
$HTTP_SESSION_VARS['cart'][$new] = 1;
      
$HTTP_SESSION_VARS['total_price'] = calculate_price($HTTP_SESSION_VARS['cart']);
      
$HTTP_SESSION_VARS['items'] = calculate_items($HTTP_SESSION_VARS['cart']);
      
$HTTP_SESSION_VARS['shoesize'] =  calculate_shoesize($HTTP_SESSION_VARS['cart']);
    
  }
  if(isset(
$HTTP_POST_VARS['save']))
  {   
    foreach (
$HTTP_SESSION_VARS['cart'] as $prdnumber => $qty)
    {
         foreach (
$HTTP_SESSION_VARS['cart'] as $prdnumber => $shoesize)
    {
             
      if(
$HTTP_POST_VARS[$prdnumber]=='0')
        unset(
$HTTP_SESSION_VARS['cart'][$prdnumber]);
      else 
        
$HTTP_SESSION_VARS['cart'][$prdnumber] = $HTTP_POST_VARS[$prdnumber];
        
//$HTTP_SESSION_VARS['cart'][$shoesize] = $HTTP_POST_VARS[$shoesize];
    
}
    
$HTTP_SESSION_VARS['total_price'] = calculate_price($HTTP_SESSION_VARS['cart']);
    
$HTTP_SESSION_VARS['items'] = calculate_items($HTTP_SESSION_VARS['cart']);
    
$HTTP_SESSION_VARS['shoesize'] = calculate_shoesize($HTTP_SESSION_VARS['cart']);
  
  }
}

  
do_html_header('Your shopping cart');

  if(
$HTTP_SESSION_VARS['cart']&&array_count_values($HTTP_SESSION_VARS['cart']))
    
display_cart($HTTP_SESSION_VARS['cart']);
  else
  {
    echo 
'<p>There are no items in your cart</p>';
    echo 
'<hr />';
  }