Put the item into an array that *should* be used for the chart
Session Class (top of page, before ANY content);
var chart = new Array(); // The chart
var numInChart; // Number of items in the chart
/* Class Constructor */
@session_start(); // Starts the session
getChart(); // Gets the chart from the session
$x = 0;
$this->chart[$x] = $_SESSION['chart_'.$x];
$this->numInChart = $x;
$t = $this->numInChart + 1;
$_SESSION['chart_'.$t] = $itemId;
getChart(); // Re-check the chart
$session = new Session;
To make it easier, I have used a class for the chart.
To add an item to the chart, call $session->addToChart($itemID); this adds another variable into the session. You should have an ID for all items so that you use as little data as possible and stop many possible errors.
When the class starts, its starts with $sesson->Session(). This then calls the getChart(); function which gets all of the chart and how many items are in it.
You can get an item from the chart by using $session->chart[ $num ]. You should use a loop to get all of the items.
You can get the total number of items in the chart by using $session->numInChart.
If you don't understand what I am saying then please tell me, I will the re-write this post.