...

View Full Version : creeating sub total and total columns in a table



mikeberish
03-21-2010, 05:08 PM
Not sure if thisis a PHP question, if not direct me the correct forum.

I am setting up a page to register for an event. I would like to have the places in the form where there is a cost involved extend a sub total based on the number of people attending each event ( times a cost I can insert) to the right and then have a grand total at the bottom of these subtotals.

I have CS4 and thougth it would provide an easy way of inserting these calculations but I just can't figure it out.

My code is posted below. The rows I would like to have subtotal are:
" 3 Event Package"
"Friday Reception"
"Saturday Picnic"
"Saturday Dinner/Dance"
"Sunday Golf"

Then total those at the bottom.



<?php require_once('../Connections/RegDBConnection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO RegDB (GradYear, LName, FName, SpouseFName, Phone, email, StreetAddress, City, `State`, Zip, HotelRooms, FriSocial, SatRHSTour, SatPicnic, SunOtherEvent, SatDance, SunGolf, SunBrunch, ICanHelp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['GradYear'], "date"),
GetSQLValueString($_POST['LName'], "text"),
GetSQLValueString($_POST['FName'], "text"),
GetSQLValueString($_POST['SpouseFName'], "text"),
GetSQLValueString($_POST['Phone'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['StreetAddress'], "text"),
GetSQLValueString($_POST['City'], "text"),
GetSQLValueString($_POST['State'], "text"),
GetSQLValueString($_POST['Zip'], "int"),
GetSQLValueString($_POST['HotelRooms'], "int"),
GetSQLValueString($_POST['FriSocial'], "int"),
GetSQLValueString($_POST['SatRHSTour'], "int"),
GetSQLValueString($_POST['SatPicnic'], "int"),
GetSQLValueString($_POST['SunOtherEvent'], "int"),
GetSQLValueString($_POST['SatDance'], "int"),
GetSQLValueString($_POST['SunGolf'], "int"),
GetSQLValueString($_POST['SunBrunch'], "int"),
GetSQLValueString($_POST['ICanHelp'], "text"));

mysql_select_db($database_RegDBConnection, $RegDBConnection);
$Result1 = mysql_query($insertSQL, $RegDBConnection) or die(mysql_error());

$insertGoTo = "ThanksForReg.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO RegDB (GradYear, LName, FName, SpouseFName, Phone, email, StreetAddress, City, `State`, Zip, FriSocial, SatRHSTour, SatPicnic, SatDance, SunGolf, SunBrunch, SunOtherEvent, HotelRooms, ICanHelp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['GradYear'], "date"),
GetSQLValueString($_POST['LName'], "text"),
GetSQLValueString($_POST['FName'], "text"),
GetSQLValueString($_POST['SpouseFName'], "text"),
GetSQLValueString($_POST['Phone'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['StreetAddress'], "text"),
GetSQLValueString($_POST['City'], "text"),
GetSQLValueString($_POST['State'], "text"),
GetSQLValueString($_POST['Zip'], "int"),
GetSQLValueString($_POST['FriSocial'], "int"),
GetSQLValueString($_POST['SatRHSTour'], "int"),
GetSQLValueString($_POST['SatPicnic'], "int"),
GetSQLValueString($_POST['SatDance'], "int"),
GetSQLValueString($_POST['SunGolf'], "int"),
GetSQLValueString($_POST['SunBrunch'], "int"),
GetSQLValueString($_POST['SunOtherEvent'], "int"),
GetSQLValueString($_POST['HotelRooms'], "int"),
GetSQLValueString($_POST['ICanHelp'], "text"));

mysql_select_db($database_RegDBConnection, $RegDBConnection);
$Result1 = mysql_query($insertSQL, $RegDBConnection) or die(mysql_error());

$insertGoTo = "ThanksForReg.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO RegDB (GradYear, LName, FName, SpouseFName, Phone, email, StreetAddress, City, `State`, Zip, HotelRooms, FriSocial, SatRHSTour, SatPicnic, SunOtherEvent, SatDance, SunGolf, SunBrunch, ICanHelp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['GradYear'], "date"),
GetSQLValueString($_POST['LName'], "text"),
GetSQLValueString($_POST['FName'], "text"),
GetSQLValueString($_POST['SpouseFName'], "text"),
GetSQLValueString($_POST['Phone'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['StreetAddress'], "text"),
GetSQLValueString($_POST['City'], "text"),
GetSQLValueString($_POST['State'], "text"),
GetSQLValueString($_POST['Zip'], "int"),
GetSQLValueString($_POST['HotelRooms'], "int"),
GetSQLValueString($_POST['FriSocial'], "int"),
GetSQLValueString($_POST['SatRHSTour'], "int"),
GetSQLValueString($_POST['SatPicnic'], "int"),
GetSQLValueString($_POST['SunOtherEvent'], "int"),
GetSQLValueString($_POST['SatDance'], "int"),
GetSQLValueString($_POST['SunGolf'], "int"),
GetSQLValueString($_POST['SunBrunch'], "int"),
GetSQLValueString($_POST['ICanHelp'], "text"));

mysql_select_db($database_RegDBConnection, $RegDBConnection);
$Result1 = mysql_query($insertSQL, $RegDBConnection) or die(mysql_error());

$insertGoTo = "ThanksForReg.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Randolph Ro-Hawk Grand Reunion 2010 Registration</title>
<style type="text/css">
<!--
.style1 {font-size: 50px}
.style12 {font-size: 24px; font-weight: bold; color: #FF0000; }
.style17 {color: #0000FF;
font-size: 36px;
}
.style2 {font-size: 75px;
color: #0000FF;
}
.style3 {font-size: 24px;
font-weight: bold;
}
.style6 {
font-size: 14px;
color: #009;
}
.style9 {color: #FF0000}
.font16pt {
font-size: 16px;
}
-->
</style>
</head>

<body>
<p align="center"><span class="style1"><span class="style2">Registration</span></span></p>
<p align="center"><span class="style1">Randolph Ro-Hawk 2010 Grand Reunion</span></p>
<p align="center"><span class="style12">This is the real deal!<br />
Complete this form to register.</span></p>
<p align="center" class="style17">Just Want to Get on the E-Mail List?</p>
<p align="center" class="font16pt">If you want to get on the e-mail list to keep track of reunion info,<br />
just complete the Registration <span class="style9"><br />
**required information**</span> <br />
and leave all the other info blank. </p>
<p align="center" class="style6">Ro-Hawks married to Ro-Hawks please register seperately<br />
so we identify all the Ro-Hawks attending. Thanks </p>
<p align="center" class="style6"><span class="style17">Need more event info and pricing<br />
<a href="mainframe.html">Go to the Home Page</a></span></p>
<p align="center" class="style6">Please enter the total number of people attending each event.<br />
<span class="style9">**required information**</span></p>
<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
<table border="2" align="center" cellpadding="2">
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="style9">**</span>Graduation Year<span class="style9">**</span>:</td>
<td><input type="text" name="GradYear" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="style9">**</span>Last Name<span class="style9">**</span>:<br />
Maiden Name, Space, Married<br />
if applicable</td>
<td><input type="text" name="LName" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="style9">**</span>First Name<span class="style9">**</span>:</td>
<td><input type="text" name="FName" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Spouse First Name:</td>
<td><input type="text" name="SpouseFName" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Phone:</td>
<td><input type="text" name="Phone" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="style9">**</span>Email<span class="style9">**</span>:</td>
<td><input type="text" name="email" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Street Address:</td>
<td><input type="text" name="StreetAddress" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">City:</td>
<td><input type="text" name="City" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">State:</td>
<td><input type="text" name="State" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Zip:</td>
<td><input type="text" name="Zip" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">3 Event Package:<br />
$105/person</td>
<td><input type="text" name="HotelRooms" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Friday Reception:<br />
$30/person</td>
<td><input type="text" name="FriSocial" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Saturday RHS Tour:</td>
<td><input type="text" name="SatRHSTour" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Saturday Picnic:<br />
Adult (14 or older) $15/person</td>
<td><input type="text" name="SatPicnic" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Saturday Picnic:<br />
Kids (&lt;14) No Charge<br />
Must Register</td>
<td><input type="text" name="SunOtherEvent" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Saturday Dinner/Dance:<br />
$65/person</td>
<td><input type="text" name="SatDance" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Sunday Golf:<br />
$40/person deposit<br />
actual fee TBD</td>
<td><input type="text" name="SunGolf" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><p>Sunday Forest Waters Club Event:<br />
fee TBD<br />
registration required
</p></td>
<td><input type="text" name="SunBrunch" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Comments:</td>
<td><input type="text" name="ICanHelp" value="" size="32" /></td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td><input type="submit" value="Register for Grand Reunion 2010" /></td>
<td>&nbsp;</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form2" />
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p></p>
</body>
</html>

mikeberish
03-21-2010, 05:20 PM
I'd even be OK with having an update button to make the totals happen, I'm just not sure how to submit the data while getting the data back to the same page, then doing a final sbmit and not make a new record.

Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum