Hi, I have a shopping cart that stores the product ID and the quantity in a session called 'cart'. Before I add the 'cart' information to the database i selialize the session to make it database friendly.
What I want to do is display this info after it has been stored on an order history page. I have used the the unserialize function and then printed out the result which give me something like:
Array
(
[3] => 7
)
Where 3 being the Product ID and 7 being the quantity. Does anyone know how I could display a customer friendly result, for example have a datadase query to say SELECT * FROM product WHERE product.product_id = [3] thefirst result in the array, and display the quantity result [7] in a field?
If anyone could help me out It'll help me loads!!
Thanks!
ADD TO SHOPPING CART CODE
// Check if the cart already contains one of these prints.
//cid = Product ID
if (isset ($_SESSION['cart'][$cid])) {
$qty = $_SESSION['cart'][$cid] + 1;
} else {
$qty = 1;
}
// Add to the cart session variable.
$_SESSION['cart'][$cid] = $qty;
CHECKOUT CODE
// Retrieve all of the information for the prints in the cart.
$query = 'SELECT * FROM cartridge WHERE cartridge.cartridge_id IN (';
foreach ($_SESSION['cart'] as $key => $value) {
$query .= $key . ',';
}
$query = substr ($query, 0, -1) . ') ORDER BY cartridge.model ASC';
$result = mysql_query ($query);
SUBMIT ORDER CODE
$c = addslashes (serialize($_SESSION['cart']));
UNSERIALIZE AND DISPLAY ARRAY (ORDER HISTORY CODE)
$cart = unserialize (stripslashes($row['cart']));
echo '<pre>';
print_r ($cart);