Q1. rewrite the exercise on April 4 by adding the following operations: 1) In th
ID: 3706659 • Letter: Q
Question
Q1. rewrite the exercise on April 4 by adding the following operations:
1) In the php script, create an associative array named $order that stores the following values:
- the number of cheese toppings;
- the number of pepperoni toppings;
- the number of ham toppings;
- the size of the ordered pizza;
- the number of the ordered pizza;
- the total cost of the order;
- the discount rate;
- the total cost after the discount.
2) the script assigns the values collected from the following fields:
- the number of each topping;
- the size of the ordered pizza;
- the number of the ordered pizza;
as the values of the elements of this array.
3) after calculating the total cost for an order, add the following values as the values of the elements of this array:
- the total cost of the order;
- the discount rate;
- the total cost after the discount;
as the values of the elements of this array.
4) applying foreach loop to print each element (key and value) of the associative array as a table. The text alignment, font size, and text color will be specified by a embedded css script that is generated by the php script.
exercise on April 4 code
// 1.html
<html>
<head>
<title>Pizza</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Pizza Order Form</h2></br>
<form id="pizzaform" action="1.php" method="post">
<p>Provide what you like and then you will know your total cost for your order.</p></br>
<label for="cheese">the number of cheese toppings</label>
<input id="cheese" type="text" name="cheese"></br></br>
<label for="pepperoni">the number of pepperoni toppings</label>
<input id="pepperoni" type="text" name="pepperoni"></br></br>
<label for="ham">the number of ham toppings</label>
<input id="ham" type="text" name="ham"></br></br>
<label for="size">the size of the selected pizza</label>
<select id="size" name="size">
<option value="small">Small</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
</select></br></br>
<label for="pizzas">how many pizzas do your order?</label>
<input id="pizzas" type="text" name="pizzas"></br></br>
<button id="total" name="calculate">Calculate Total</button>
<button>Reset</button>
</form>
<script>
function validate() {
var value = true;
var cheese = document.getElementById("cheese");
if(cheese.value<0||cheese.value>10) {
alert("the number of the toppings must be 0<=cheese<=10");
value = false;
}
var pep = document.getElementById("pepperoni");
if(pep.value<0||pep.value>10) {
alert("the number of the toppings must be 0<=pep<=10");
value = false;
}
var ham = document.getElementById("ham");
if(ham.value<0||ham.value>10) {
alert("the number of the toppings must be 0<=ham<=10");
value = false;
}
var pizzas = document.getElementById("pizzas");
if(pizzas.value<1||pep.value>=10) {
alert("the number of the toppings must be 1<=number of pizzas<10");
value = false;
}
return value;
}
function clear() {
document.getElementById("pizzaform").reset();
}
</script>
</body>
</html>
// 1.php
<?php
if(isset($_POST['calculate']))
{
$cheese = $_POST['cheese'];
$pepperoni = $_POST['pepperoni'];
$ham = $_POST['ham'];
$size = $_POST['size'];
if($size=="small")
$size = 10;
elseif ($size=="medium")
$size = 12;
elseif ($size=="large")
$size = 14;
$pizzas = $_POST['pizzas'];
$total = $pizzas*($size+$cheese*2+$pepperoni*2+$ham*2);
$discount = 0;
if ($total>30 AND $total<=50)
$discount = 5;
elseif ($total>50 AND $total<=75)
$discount = 10;
elseif ($total>75 AND $total<=100)
$discount = 15;
elseif ($total>100)
$discount = 20;
else
$discount = 0;
$payment = ($total - ($total * ($discount / 100)));
}
?>
<html>
<head>
<link rel="stylesheet" href="main.css">
<title>Order</title>
</head>
<body>
<p class="large">We have received your order, thank you!</p>
<p class="large">The detail of your order is below:</p>
<ul>
<li>the number of cheese toppings=<?php echo $cheese;?></li>
<li>the number of pepperoni toppings=<?php echo $pepperoni; ?></li>
<li>the number of ham toppings=<?php echo $ham; ?></li>
<li>the size of the ordered pizza=<?php echo $size; ?></li>
<li>the number of the ordered pizza=<?php echo $pizzas; ?></li>
</ul>
<h1>Your total cost is: <?php echo $total; ?></h1>
<table border="1">
<tr>
<th colspan="8">Order Information</th>
</tr>
<tr>
<td colspan="3" align="center">toppings</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>cheese</td>
<td>pepperoni</td>
<td>ham</td>
<td>size</td>
<td>number</td>
<td>cost</td>
<td>discount</td>
<td>payment</td>
</tr>
<tr>
<td><?php echo $cheese;?></td>
<td><?php echo $pepperoni; ?></td>
<td><?php echo $ham; ?></td>
<td><?php echo $size; ?></td>
<td><?php echo $pizzas; ?></td>
<td><?php echo $total; ?></td>
<td><?php echo $discount; ?></td>
<td><?php echo $payment?></td>
</tr>
</table>
</body>
</html>
// style.css
body
{
background-color: pink;
}
label,p,h2
{
color: blue;
}
#total
{
margin-left: 80px;
}
h1
{
color: red;
}
.large
{
color: black;
font-size: 105%;
}
// webpage screenshots
127.0.0. 1/csc355/march%2028/1.html Pizza Order Form 127.0.0.1 says: the number of the toppings must be 0Explanation / Answer
<!-- 1.php -->
<?php
if(isset($_POST['calculate']))
{
//------------------------------------------------------------
//ANSWER-1 FROM HERE
$order = array(
'cheese' => 0,
'pepperoni' => 0,
'ham' => 0,
'size' => 0,
'pizzas' => 0,
'total' => 0,
'payment' => 0,
'discount' => 0,
);
//------------------------------------------------------------
//ANSWER-2 FROM HERE
$order['cheese'] = $_POST['cheese'];
$order['pepperoni'] = $_POST['pepperoni'];
$order['ham']= $_POST['ham'];
$order['size'] = $_POST['size'];
if($order['size']=="small")
$order['size'] = 10;
elseif ($order['size']=="medium")
$order['size'] = 12;
elseif ($order['size']=="large")
$order['size'] = 14;
$order['pizzas'] = $_POST['pizzas'];
//------------------------------------------------------------
//ANSWER-3 FROM HERE
$order['total'] = $order['pizzas']*($order['size']+$order['cheese']*2+$order['pepperoni']*2+ $order['ham'] *2);
$order['discount'] = 0;
if ($order['total']>30 AND $order['total']<=50)
$order['discount'] = 5;
elseif ($order['total']>50 AND $order['total']<=75)
$order['discount'] = 10;
elseif ($order['total']>75 AND $order['total']<=100)
$order['discount'] = 15;
elseif ($order['total']>100)
$order['discount'] = 20;
else
$order['discount'] = 0;
$order['payment'] = ($order['total'] - ($order['total'] * ($order['discount'] / 100)));
}
//------------------------------------------------------------
?>
<html>
<head>
<link rel="stylesheet" href="main.css">
<title>Order</title>
<style>
body{
color : red;
}
#header{
color : black;
}
</style>
</head>
<body bgcolor="#ffda90">
<b id = "header"> Order Information </b>
<p>
<table border="1" cellpadding="4" cellspacing="4" width="20%">
<!--ANSWER-4 FROM HERE -->
<?php
foreach ($order as $key => $value) {
if($key == 'payment')
$key1 = "after_reduction";
else
$key1 = $key;
if($key1 == 'after_reduction' || $key1 == 'total')
echo "<tr><td><center>".$key1."</center></td><td><center>$".$value."</center></td></tr>";
else if($key1 == 'discount')
echo "<tr><td><center>".$key1."</center></td><td><center>".$value."%</center></td></tr>";
else
echo "<tr><td><center>".$key1."</center></td><td><center>".$value."</center></td></tr>";
}
?>
<!--ANSWER-4 ENDS -->
</table>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.