ThomasJSmart
Programmer
- Sep 16, 2002
- 634
hi ppl iv made this very simple shooping cart prototype, its my first cart
remarks and comments are welcome.
there is an online working version here:
comments are welcome,
Thomas
I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!

Code:
<?
session_start();
if (!isset($_SESSION['products'])){$_SESSION['products'] = "";}
if (isset($_GET['add'])){$_SESSION['products'] = $_SESSION['products'].".".$_GET['add']; echo "<body onLoad=\"window.location='index.php'\">";}
// Database Connect function
function connectdb()
{
global $db;
$db = mysql_connect("localhost", "******","*******");
mysql_select_db("webshop",$db);
}
// get items from database
connectdb();
$result = mysql_query("SELECT * from items",$db);
echo "Items in database:<br><br>";
while ($myrow = mysql_fetch_array($result))
{
$id = $myrow['id'];
$cat = $myrow['cat'];
$title = $myrow['title'];
$info = $myrow['info'];
$cost = $myrow['cost'];
echo "ID: $id<br>Cat: $cat<br><a href='index.php?add=$id'>Title: $title</a><br>Info: $info<br>Cost: $cost<br><br>";
} // end get results loop
mysql_close();
$itemarr = explode(".",$_SESSION['products']);
$itemarr = array_slice ($itemarr, 1);
$acv = array_count_values ($itemarr);
$ak = array_keys ($acv);
$totp = count($ak);
$totsub = 0;
if ($totp > 0)
{
echo "Items u have selected:<br><br><table width='400'>";
for ($n = 0; $n < $totp; $n++)
{
$thisid = $ak[$n];
connectdb();
$result = mysql_query("SELECT * from items WHERE id='$thisid'",$db);
while ($myrow = mysql_fetch_array($result))
{
$title = $myrow['title'];
$cost = $myrow['cost'];
$thiscost = $cost*($acv[$n+1]);
$totsub += $thiscost;
echo "<tr><td>$title</td><td>x".$acv[$n+1]."</td><td> E $cost</td></tr>";
} // end get results loop
mysql_close();
}
echo "<tr><td></td><td>Subtotal:</td><td> E $totsub";
$btw = round(($totsub / 100)*19);
echo "<tr><td></td><td>BTW:</td><td> E $btw";
$totcos = $totsub + $btw;
echo "<tr><td></td><td>BTW:</td><td> E $totcos</td></tr></table>";
}
?>
there is an online working version here:
comments are welcome,
Thomas
I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!