PHPBuilder - Mini Shopping Basket with only PHP4 Sessions Page 3



RSS Twitter
Articles Application Architecture

Mini Shopping Basket with only PHP4 Sessions - Page 3

by: Evert Smith
|
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.

<?php

if ($basket!=""){
    
//add item to basket.
}

?>
Snippet 2: Printing the basket to the browser

<?php

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 
"<BR>\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);
}

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

« Previous Page
1
|
2
|
3
|
4
|
5
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Evert Smith

Comment:



Comment:

(Maximum characters: 1200). You have characters left.