#native_company# #native_desc#
#native_cta#

Basket example using basket class

By Hugo Saavedra
on August 24, 2000

Version: 0.1

Type: Sample Code (HOWTO)

Category: Shopping Carts

License: GNU General Public License

Description: This example shows how to work with the class “basket”

<%
include "basket.inc";
//The object need to be here, first of any output to the browser
// Refer to cookie reasons
$b=new basket();
switch($action){
case "A":
$b->additem($id,1);
break;
case "R":
$b->removeitem($id);
break;
}

%>
<body text="#000080" link="#0000FF" vlink="#800080" alink="#FF0000" bgcolor="#FFFFFF">
<pre>
ID	ITEM		Price
23	Notebook 	3500	<a href="<? echo $PHP_SELF; ?>?action=A&id=23&q=1">Add</a>
10	Pad		10	<a href="<? echo $PHP_SELF; ?>?action=A&id=10&q=1">Add</a>
</pre>
<pre>
<%

if(!$b->empty) {
echo "Items in your shopping cart:<br>ID	ITEM	Q<br>";
while(list($x,$y)=each($b->items))
{ echo "$x	NN	$y	<a href="$PHP_SELF?action=R&id=$x">Remove</a><br>";
}
}
%></pre>