Hey guys,
I’ve coded this page to handle the shopping basket on my site, but the idea is to have more than one shop running on the same site, so I need separate baskets for each. Obviously an instant problem with that is they share the same session id’s. Below i’ve made an example of what in my ideal world is how it’d work by defining:
$_SESSION['cart_id_$storeid'] = $sessionvalue;
But that obviously doesn’t work, how would I go about doing this? :S
Here’s my full source:
<?php
session_start();
include("dbstore.php");
$storeurl = addslashes($_GET['url']);
$getstore = mysql_query("SELECT * FROM `store` WHERE `url` = '$storeurl'") or die(mysql_error());
$store = mysql_fetch_array($getstore);
$storeid = "$store[id]";
$current = time(); //Current timestamp
// Grab shopping cart session if it exists
if(isset($_SESSION['cart_id_set'])) {
$getbasket = mysql_query("SELECT * FROM `store_basket` WHERE `id` = '".$_SESSION['cart_id']."'") or die(mysql_error());
$basket = mysql_fetch_assoc($getbasket);
$get_basket_items = mysql_query("SELECT * FROM `store_basket_items` WHERE `basketid` = '$basket[id]'") or die(mysql_error());
$total_items = mysql_num_rows($get_basket_items);
$basket_total = mysql_query("SELECT SUM(price) AS price FROM store_basket_items WHERE basketid = '$basket[id]'");
$total = mysql_fetch_array($basket_total);
$total_price_format = number_format($total[price], 2, '.', ',');
echo"<div id=\\"basket\\">$total_items Items - £$total_price_format <u>Check Out</u></div>";
// Create shopping cart session if it does not exist yet..
} else {
$current2 = time(); //Current timestamp
$countcarts = mysql_query("SELECT MAX(id) AS maximumId FROM `store_basket") or die(mysql_error());
$totalCarts = mysql_fetch_object($countcarts);
$new_totalCarts = ($totalCarts->maximumId+1);
$createcart = mysql_query("INSERT INTO `store_basket` (`id`, `timestamp`) VALUES('" . mysql_real_escape_string($new_totalCarts) . "', '" . $current2 . "')") or die(mysql_error());
$basketid = mysql_insert_id();
$sessionvalue = $basketid;
$_SESSION['cart_id'] = $sessionvalue;
$_SESSION['cart_id_set'] = 'yes';
echo"<div id=\\"basket\\">0 Items - £0.00 <u>Check Out</u></div>";
}
?>
Thanks for any help provided