hi guys.. can anyone help me with that staff?
here is my code..
$cart = $_SESSION['cart'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['id'];
$type .= ','.$_GET['type'];
} else {
$cart = $_GET['id'];
$type= $_GET['type'];
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$ca rt);
$newcart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
}
$_SESSION['cart'] = $cart;
$_SESSION['type']=$type;
function writeShoppingCa rt() {
$cart = $_SESSION['cart'];
$type= $_SESSION['type'];
if ($cart) {
$items = explode(',',$ca rt);
$types=explode( ',',$type);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($content s[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<form action="cart.ph p?action=update " method="post" id="cart">';
$output[] = '<table>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM tracks WHERE v_id = '.$id;
$result = mysql_query($sq l);
$row = mysql_fetch_obj ect($result);
//extract($row);
$output[] = '<tr>';
$output[] = '<td><a href="basket.ph p?action=delete &id='.$id.'" class="r">Remov e</a></td>';
$output[] = '<td>'.$row->title.'</td>';
$output[] = '<td><input type="text" name="qty'.$id. '" value="'.$qty.' " size="3" maxlength="3" /></td>';
$output[] = '</tr>';
}
$output[] = '</table>';
//$output[] = '<div><button type="submit">U pdate cart</button></div>';
$output[] = '</form>';
} else {
$output[] = '<p>You shopping basket is empty.</p>';
}
return join('',$output );
}
echo writeShoppingCa rt();
in the result i have got the title of the track tha have been added to the basket and how mush times the user added it to the basket..
Now i am getting and another value which is the type of the track .
example. <a href="basket.ph p?id=19&type=2" >Add to basket</a>
i am storing this value to the _session['type'] and i want to have this result.
Title
Norah Jones //Which id=12
Number 0f Clicks
12 //Which is the $gty value
Type
2 //the value of the session.. that id=12 when the user clicked
Can anybody help me..
thanks you..
i hope you understand what i want..
here is my code..
$cart = $_SESSION['cart'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['id'];
$type .= ','.$_GET['type'];
} else {
$cart = $_GET['id'];
$type= $_GET['type'];
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$ca rt);
$newcart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
}
$_SESSION['cart'] = $cart;
$_SESSION['type']=$type;
function writeShoppingCa rt() {
$cart = $_SESSION['cart'];
$type= $_SESSION['type'];
if ($cart) {
$items = explode(',',$ca rt);
$types=explode( ',',$type);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($content s[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<form action="cart.ph p?action=update " method="post" id="cart">';
$output[] = '<table>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM tracks WHERE v_id = '.$id;
$result = mysql_query($sq l);
$row = mysql_fetch_obj ect($result);
//extract($row);
$output[] = '<tr>';
$output[] = '<td><a href="basket.ph p?action=delete &id='.$id.'" class="r">Remov e</a></td>';
$output[] = '<td>'.$row->title.'</td>';
$output[] = '<td><input type="text" name="qty'.$id. '" value="'.$qty.' " size="3" maxlength="3" /></td>';
$output[] = '</tr>';
}
$output[] = '</table>';
//$output[] = '<div><button type="submit">U pdate cart</button></div>';
$output[] = '</form>';
} else {
$output[] = '<p>You shopping basket is empty.</p>';
}
return join('',$output );
}
echo writeShoppingCa rt();
in the result i have got the title of the track tha have been added to the basket and how mush times the user added it to the basket..
Now i am getting and another value which is the type of the track .
example. <a href="basket.ph p?id=19&type=2" >Add to basket</a>
i am storing this value to the _session['type'] and i want to have this result.
Title
Norah Jones //Which id=12
Number 0f Clicks
12 //Which is the $gty value
Type
2 //the value of the session.. that id=12 when the user clicked
Can anybody help me..
thanks you..
i hope you understand what i want..
Comment