arrays

I need help with setting up my array. What the code needs to do is if you click on one of the checkboxes it should return what you have ordered and the price which are .25 cents per item. I have figured out how to get it to show what the item is that is clicked on. For example if someone chooses chicken it will echo what they ordered which is chicken, but I have absolutely no idea how and where to add in a price for each of the items and only show the price for the items they picked and totaled up. Please help, I'm stuck.

[code]

Please select your pizza toppings Pepperoni
Sausage
Bacon
Ham
Ground beef
Chicken

[/code]

[php]

<?php echo "You order a pizza with
"; foreach($_POST[options] as $ingredients){ echo"With $ingredients
"; } ?>

[/php]

Hello

i added a little to your script, this should do what you need:

[php]<?php
//Handle the form
if(isset($_POST[‘submit’]))
{
$perTopping = .25; // .25 pence/cents per topping.
$extraToppings = count($_POST[‘options’]); // count how many toppings

// show the price for the individual toppings cost
echo '<p>Extra toppings cost ' . $perTopping . ' each</p>';

echo 'You ordered a ';
// check if any extra toppings?
if($extraToppings == 0)
{
	echo "plain pizza."; // no extra toppings 
}
else
{
	echo 'pizza with ' . $extraToppings . ' extra toppings<br>'; // we want a nice pizza :)
}

// display the toppings
foreach($_POST['options'] as $ingredients)
{
	echo "$ingredients<br>";
}

// subtotal:
$toppingsTotal = number_format($perTopping * $extraToppings, 2);
echo '<p>Toppings Total: ' . $toppingsTotal . '</p>';

} // End of submission IF
?>
[/php]
[php]// output based on 3 toppings chosen:
Extra toppings cost 0.25 each

You ordered a pizza with 3 extra toppings
Sausage
Ham
Chicken
Toppings Total: 0.75[/php]

hope this helps
:wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service