#native_company# #native_desc#

Mini Shopping Basket with only PHP4 Sessions Page 3

By Evert Smith
on August 17, 2000

Snippet 1: Checking for new item to be added
This is a regular IF Statement looking for the value of the variable $basket.


if ($basket!=""){

//add item to basket.



Snippet 2: Printing the basket to the browser


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 .




"$amount $name $price";



} 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.








The result of this piece of code equals nothing. The items are not filled, the basket always empty and therefore the basket never displayed. So let’s add some items to this basket.