Jump to content

Online Order System Looping Problem!


mikebarbaro

Recommended Posts

Hello,

 

I am designing an online ordering system for a restaurant. I have a menu with check boxes by each item where the customer can select which items they desire. The menu is located at tandoorpgh.com/placeanorder

 

The problem is that when the order is processed I need it to store each checked off item as a session variable. In the following code, it only selects the first item checked and not the rest if there is more than one. Any help is appreciated!

 

$item=$_POST['title'];
foreach ($item as $itemname)
{

$query = mysql_query("SELECT * FROM `menu` WHERE title = '$itemname'");
while($row = mysql_fetch_array($query)) {

	$total = $total + $row['price'];

echo "<p>" . $row['title'] . " - <span style=color:#000;>$" . $row['price'] . "</span></p>";

$allitems = $row['title'] . $row['price'];

$_SESSION['items'] = $allitems;
$_SESSION['total'] = $total;
}
}

Link to comment
Share on other sites

Well, my biggest confusion is the following code snippet containing the echo displays all items that were checked off from the form, yet when I try and save them as a session variable it only displays one item.

 

echo "<p>" . $row['title'] . " - <span style=color:#000;>$" . $row['price'] . "</span></p>";

 

Say three items from the menu at tandoorpgh.com/placeanorder are checked off. When they come to this page to review their order the echo statement displays all three, but I cannot figure out why they won't save as a session variable?

 

I've tried

$_SESSION['items'] = $row['title'];

within the loop statement but no luck...

 

Do I maybe need to loop through the whole array?

 

Any help is very much appreciated!

Link to comment
Share on other sites

oh i see. well each time you loop through that while you are overwriting the session var from the previous loop. so you might want to do something like:

 

$_SESSION['items'][] = $allitems;
$_SESSION['total'] += $total;

 

that will add up the total and create an array of items.

 

Link to comment
Share on other sites

ok can you post the output of this

<?PHP
echo "<pre>" . print_r($_POST,true) . "</pre>";

$item=$_POST['title'];
foreach ($item as $itemname)
{

$query = mysql_query("SELECT * FROM `menu` WHERE title = '$itemname'");
while($row = mysql_fetch_array($query)) {

	$total = $total + $row['price'];

echo "<p>" . $row['title'] . " - <span style=color:#000;>$" . $row['price'] . "</span></p>";

$allitems = $row['title'] . $row['price'];

$_SESSION['items'][] = $allitems;
$_SESSION['total'] += $total;
}
}

echo "<pre>" . print_r($_SESSION,true) . "</pre>";

?>

 

Link to comment
Share on other sites

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.