Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/130846-session-array-with-three-variables/
Share on other sites

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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.