in my cart implementation… am getting all the selected produts total…
Now i wants to display this total and number of items in cart…in each every page user visits until he go to checkout…
my code as follows…
if (count($_SESSION["cart"]) <1)
{
$msg="Your Cart is empty";
}
if (isset($_GET["shopping_cart"]) || isset($_POST["shopping_cart"]))
{
if (isset($_GET["productID"]) && (int)$_GET["productID"]>0) //add product to cart with productID=$_GET["productID"]
{
//$is = $is[0];
//$_SESSION['cart'] contains product IDs
//$_SESSION['counts'] contains item quantities ($_SESSION['counts'][$i] corresponds to $_SESSION['cart'][$i])
//$_SESSION['cart'][$i] == 0 means $i-element is 'empty' (does not refer to any product)
if (!isset($_SESSION["cart"]))
{
$_SESSION["cart"] = array();
$_SESSION["counts"] = array();
}
//check for current product in visitor's shopping cart content
$i=0;
while ($i<count($_SESSION["cart"]) && $_SESSION["cart"][$i] != $_GET["productID"]){
$i++;
}
if ($i < count($_SESSION["cart"])) //increase current product's item quantity
{
$_SESSION["counts"][$i]++;
}
else //no such product in the cart - add it
{
$_SESSION["cart"][] = $_GET["productID"];
$_SESSION["counts"][] = 1;
}
}
//================================ remove product with productID == $remove =================
if (isset($_GET["remove"]) && (int)$_GET["remove"] > 0)
{
$i=0;
while ($i<count($_SESSION["cart"]) && $_SESSION["cart"][$i] != (int)$_GET["remove"])
$i++;
if ($i<count($_SESSION["cart"]))
$_SESSION["cart"][$i] = 0;
}
//===================================================================================
//================================ update shopping cart content ============================
if (isset($_POST["update"])) //
{
foreach ($_POST as $key => $val)
if (strstr($key, "count_"))
{
if ($val > 0)
{
for ($i=0; $i<count($_SESSION["cart"]); $i++)
{
if ($_SESSION["cart"][$i] == str_replace("count_","",$key))
{
$_SESSION["counts"][$i] = floor($val);
}
}
}
else //remove
{
$i=0;
while ($_SESSION["cart"][$i] != str_replace("count_","",$key) && $i<count($_SESSION["cart"])) $i++;
$_SESSION["cart"][$i] = 0;
}
}
$location="<script>window.location='mycart.php?shopping_cart=yes'</script>";
echo $location;
unset($location);
}
//===================================================================================
//================================ clear whole cart ======================================
if (isset($_GET["clear"]) && $_GET["clear"] =='clear')
{
unset($_SESSION["cart"]);
unset($_SESSION["counts"]);
$msg="Your Cart is empty";
}
//===================================================================================
//================================ save cart ===========================================
if (isset($_GET["save"]) && $_GET["save"] =='save') //save cart
{
if(!isset($_SESSION['email'])){
$location="<script>window.location='login.php?goto=".$_SERVER['PHP_SELF']."'</script>";
echo $location;
unset($location);
}
else{
$location="<script>window.location='save.php'</script>";
echo $location;
unset($location);
}
}
//===================================================================================
}
and inside the for loop.
..................
..................
$tmp = array(
$_SESSION["cart"][$i],
$arr_items['txtname'],
$_SESSION["counts"][$i],
($_SESSION["counts"][$i]*$pri_vat)." ".$currency_iso_3
);
$k += $_SESSION["counts"][$i]*$pri_vat;
.............................
.............................
can anyone help with this issue pls…