0){ // If the basket contains items check for double entries foreach ($ses_basket_name as $basket_item){ // Run through the array that contains the name and // check if it matches the item from the href. if ($basket_item==$basket){ // Set Flag to 1 if the item is already in the basket. $double=1; // Remember the position of the item to be updated $basket_position=$basket_position_counter; } $basket_position_counter++; //Increment actual Position in basket } } // Update the basket if ($double==1){ // Update amount and price at position $basket_position // if the item is already in your basket $oldamount=$ses_basket_amount[$basket_position]; $ses_basket_amount[$basket_position]++; $amount=$ses_basket_amount[$basket_position]; $oldprice=$ses_basket_price[$basket_position]; //update the price $newprice=($oldprice/$oldamount)*$amount; $ses_basket_price[$basket_position]=$newprice; }else{ // Add new item at end of array // if it is not in your basket $ses_basket_name[]=$basket; $ses_basket_amount[]=1; $ses_basket_price[]=$price; $ses_basket_id[]=$id; $ses_basket_items++; } } else { // There is no basket registered // Place Snipplet 3 here. It creates a new basket and registers it with // the session. // Put the item counter to 1 $ses_basket_items=1; // Fill the 4 arrays at position 0 with the values from the href link // shown in the 'adding the link to your page' part $ses_basket_name[0]=$basket; $ses_basket_amount[0]=1; $ses_basket_price[0]=$price; $ses_basket_id[0]=$id; // register the new basket in the session session_register("ses_basket_items"); session_register("ses_basket_name"); session_register("ses_basket_amount"); session_register("ses_basket_price"); session_register("ses_basket_id"); } } // All there is left is Snipplet 2. It displays the basket if there are items in it. // Add it here. if ($ses_basket_items>0){ // If there are items in your basket for ($basket_counter=0;$basket_counter<$ses_basket_items;$basket_counter++){ // Go through the basket and print out each line // You can of course format this to be in a table // The formatting is needed to display the cents of your order. .00 will not display // if not formatted . $price=sprintf("%01.2f",$ses_basket_price[$basket_counter]); $amount=$ses_basket_amount[$basket_counter]; $name=$ses_basket_name[$basket_counter]; echo "$amount $name $price"; echo "
\n"; } } else { // there are no articles in your basket // setting the item counter to 0 and unsetting all variables // This is a clean up here. It prevents people from getting old arrays back. $ses_basket_items=0; unset($ses_basket_name); unset($ses_basket_amount); unset($ses_basket_price); unset($ses_basket_id); } ?>