I don't have code and it's late so I apologize if this isn't that helpful...
That said, you don't need a loop to add multiple items to your shopping cart. Your session variable for your shopping cart should look something like this: $_SESSION['cart'][0] = id_for_product. Basically, everytime a product is added you add a new key=>value pair to the array. For example,
// ex. $id is the ID of the product. This could be from GET, POST, etc.
$_SESSION['cart'][] = $id;
Now you're adding a new key=>value pair to the $_SESSION['cart'] array everytime you add a new product to the cart. This way there is no overwriting. Finally, when the user checks out, you can get all the data about the products with a simple for() loop:
for ($i = 0; $i < count($_SESSION['cart']); $i++)
{
$id = $_SESSION['cart'][$i];
$result = mysql_query("SELECT * FROM products WHERE id=$id");
$row = mysql_fetch_array($result);
}
And now you have $row['productName'], $row['productPrice'], etc., all from the session variable.
I hope you understood this!