padams Posted October 31, 2008 Share Posted October 31, 2008 Is it possible to carry three bits of information in one session array? I'm working on a shopping cart for a store that sells linen. Each product has a variety of styles, so when I take the data to the checkout page I need the session to contain the product ID, style ID, and quantity ordered. Is this possible? Once in the checkout page I'd need to iterate through the session array and query the database, returning the product name, style name, quantity, and also the price of the product. Fortunately the style does not affect the price! Session is called $_SESSION['cart'][$productID][$styleID]['quantity'] I'm currently using this code to get the product name from the database: $query = "SELECT productID, name FROM products WHERE productID IN ("; foreach ($_SESSION['cart'] as $pid => $value) { $query .= $pid . ','; } $query = substr ($query, 0, -1) . ') ORDER BY name ASC'; $result = mysql_query ($query); Is there any way I can add in a bit of code that also picks up the style name from the styles table, based on the $styleID in the session? Quote Link to comment https://forums.phpfreaks.com/topic/130846-session-array-with-three-variables/ Share on other sites More sharing options...
Daniel0 Posted October 31, 2008 Share Posted October 31, 2008 You can just use an array: $_SESSION['cart'] = array( 'productID' => $productID, 'styleID' => $styleID, 'quantity' => $quantity, ); Quote Link to comment https://forums.phpfreaks.com/topic/130846-session-array-with-three-variables/#findComment-679129 Share on other sites More sharing options...
padams Posted November 2, 2008 Author Share Posted November 2, 2008 Would that put all three bits of data into the one field? I'm not sure how to then query the database to get the style information as well as the product info. The query I posted seems to get the product information I need, but how would I include something that grabs the style that the shopper chose also? The styles table has two fields: styleID and style (which is the name of the style). Quote Link to comment https://forums.phpfreaks.com/topic/130846-session-array-with-three-variables/#findComment-680728 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.