Hi,
I have attached 3 images:
- table_structure.png (that displays the structure of table called runtotals that I am working with).
- runtotals_data.png (that displays the data in the runtotals table).
- form.png (the show the form I must use to input the data from the user).
I need to have the user input the integer values as quantities in the input boxes provided for the three items.
The user want to buy: 4 cookies at a $1.00 each.
1 hotdog at $2.00
2 pizzas at 2.50.
When the apply button is selected, I want to perform a mathematical calculationof:
41.00 + 1 2.00 + 2 * 2.50 , and the resulting value 11.00 should display in the total column.
I also want to create a cumulative grand total that will display at the end.
Below is the php/html file that I wrote to generate the form data. However I just don't know how to proceed with generating the totals.
=========
<?php
include_once '../../core/init.php'; // this includes the database etc.
$sql="SELECT ID, datem, item1,item1price, item2, item2price, item3,item3price
from runtotals order by datem";
$result= mysql_query($sql);
if (!$result)
{
echo 'Error fetching items'.mysql_error();
}
else
{
while ($row = mysql_fetch_array($result))
{
$menus[] = array('ID' => $row['ID'],
'datem' => $row['datem'],
'item1' => $row['item1'],
'item1price'=> $row['item1price'],
'item2' => $row['item2'],
'item2price'=> $row['item2price'],
'item3' => $row['item3'],
'item3price'=> $row['item3price'],
);
}
}
if (isset($POST['dailybuy']) and $POST['dailybuy'] == 'Apply')
{
// NOT SURE HOW TO PROCEED....
}
?>
<? ob_flush(); ?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="../../css/primary.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="header">
<div id="logo">
<h1> St. Augustine School </h1>
</div>
</div>
<div id="wrap">
<div id="main">
<h1 class="fleft"> Menu </h1>
<div id="options" align="right">
<a href="../logout.php" class="button"> Log Out </a>
<a href="school_admin_options.html.php" class="button"> Return to Home Page </a>
</div>
<div id="content">
<form action="" method="post">
<table class="stable" width="900px">
<thead>
<tr class="th"><td>Id</td><td>Date</td><td>Daily Menu Items </td><td>Total</td></tr>
</thead>
<tbody>
<?php foreach ($menus as $menu): ?>
<tr>
<td><?php echo $menu['ID']; ?></td>
<td><?php echo $menu['datem']; ?></td>
<td>
<div>
<?php echo $menu['item1'].'-'.$menu['item1price']; ?>
<input type="text" name="q1" size="2" value="">
<?php echo $menu['item2'].'-'.$menu['item2price']; ?>
<input type="text" name="q2" size="2" value="">
<?php echo $menu['item3'].'-'.$menu['item3price']; ?>
<input type="text" name="q3" size="2" value="">
<input type="submit" name="dailybuy" value="Apply">
<input type="hidden" name="pitem1" value="<?php echo $menu['item1price'] ?>">
<input type="hidden" name="pitem2" value="<?php echo $menu['item2price'] ?>">
<input type="hidden" name="pitem3" value="<?php echo $menu['item3price'] ?>">
</div>
</td>
<td><input type="text" name="subtotal" ></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</form>
<div id="errm">
<?php echo output_errors($errors); ?>
</div>
</div>
</div>
</div>
</body>
</html>
==============
Your valuable time and consideration to help is greatly appreciated.
RCR
table_structure.png
runtotals_data.png
form_menu.png