views:

26

answers:

3

I'm finishing up an online menu for a fine dining client. For each item, the user can enter the desired quantity.

When the user finishes selecting and submits the form, I want a confirmation email to go to the user and to the restaurant owner (the same message).

In the confirmation email, I only want to display items for which they've entered a quantity. E.g.:

Foie Gras 1 $9ea
Steak au Poivre 2 $37ea

I know this is probably straightforward, but I can't conceptualize at what point the script checks for something like !="". Or something.

Here's the menu for your reference: http://www.greenroomgrille.com/valentines/

Thanks so much in advance.

+1  A: 

You could run through a foreach and concat the values that have quantities:

$order = "";
foreach ($items as $item => $quantity) {
  if ($quantity > 0)
    $order .= "{$item} {$quantity}\n";
}
print $order;

This assumes an array like this:

$items = array("Pudding" => 3, "Yogurt" => 12, "Soup" => 0, "Apples" => 0);
Jonathan Sampson
Darn you Sampson for being so quick! +1
jeerose
Hehe. Thank you, @jeerose :)
Jonathan Sampson
I had a hunch I'd need to loop through the values. Thanks for clearing it up.
patrickjwoods
A: 

It would be pretty simple, just check of the variable is empty before adding it to the body text:

if ($POST["Pudding"] <> "") { $bodyText .= "Pudding: " . $POST["Pudding"]; }

crgwbr
You're using a MySQL comparison, you'll want != instead of <>.
Cryo
oops, yep. I'm used to Python, where both will work.
crgwbr
And the variables will be in $_POST instead of $POST.
Cryo
A: 

The most straight-forward way to approach this is to iterate through all of your menu item quantity values and condition their addition to the email body like this:

if(intval($_REQUEST['CourseOne-App1']) > 0)
  $email_body .= intval($_REQUEST['CourseOne-App1']) . 'x Torchon of Foie Gras' . "\n";

if(intval($_REQUEST['CourseOne-App2']) > 0)
  $email_body .= intval($_REQUEST['CourseOne-App2']) . 'x Carpaccio' . "\n";

// etc...
Cryo
Awesome. Thanks for the specificity.
patrickjwoods