Re: Merge two variables
Posted: Sun Jan 04, 2009 10:07 pm
For each "food" i have also added a "price". I was able to multiply the 'price' with the 'amount' for each item. But I can't find a way to sum this so I'll get the total price as well. Here's the code. While $value is working fine, the $total allways gives me zero.
Any ideas?
Code: Select all
$total = $_POST['food']['price'] * $_POST['food']['amount'];
$msg = "";
foreach ($_POST["food"] as $food) {
if ($food["check"] && $food["amount"]) { // checked and at least one
$msg .= $food["amount"] . " "; // number
$msg .= $food["check"]; // name
$value = $food['price'] * $food['amount'];
$msg .= $value; // price
if ($food["extra"]) $msg .= " with " . $food["extra"]; // extra
$msg .= "\n";
}
}
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n $msg $total";