Hi Everyone,
I am taking another stab at this problem, complete with code and an
example...
Here is the issue:
I need to be able to display pounds and ounces of a given number of
pieces, the code I have does this just fine for a single route... But
what I can't seem to get through my head is how to do it for a
variable number of routes?
Here is the code I'm working with...
<?PHP
//Rural Route Weight Calculator by Jason Pruim 2008
$c = "0";
$num= "1";
//$num = $_POST['txtNum'];
$PieceWeight = $_POST['txtPieceWeight'];
$RoutePieces = $_POST['txtRoutePieces'];
$RouteNumber = $_POST['txtRoute'];
//self submitting forms
$self = $_SERVER['PHP_SELF'];
$totalWeight = ($PieceWeight * $RoutePieces) /16;
$weightExplode = explode('.', $totalWeight);
$weightOunces = ((float)('.' . $weightExplode[0])) * 16;
// Use stut's method... Seems cleaner
$explodeOunces = ($totalWeight - intval($totalWeight)) * 16;
if($_POST) {
echo <<<HTML
<div class="weightbox">
<h1>Weight calculator</h1>
<form method ='post' action='{$self}'>
<p>Weight of a single piece:<input type="text" name="txtPieceWeight"
size="5" value="{$PieceWeight}"></p>
HTML;
while ($c != $num) {
echo <<<HTML
Route Number:<input type="text" name="txtRoute" size="5"
value="{$RouteNumber}"> Number of pieces: <input type="text"
name="txtRoutePieces" value="{$RoutePieces}"size="5"><label>Total
weight of route: {$weightExplode[0]}# {$explodeOunces} Ounces</
label><BR>
HTML;
$c++;
}
echo "<BR><input type='submit' value='Calculate'></form></div>";
//DEBUG
dump_debug($RoutePieces);
dump_debug($RouteNumber);
dump_debug($_POST);
print_debug($explodeOunces);
dump_debug($weightExplode);
//END DEBUG
}else{
echo "<form method='post' action='{$self}'>";
echo "Number of routes: <input type='text' name='txtNum' size='2'><BR>
<input type='submit' value='GO'>";
echo "</form>";
}
?>
The website is: HTTP://www.raoset.com/dev/weightcalc/
I need help! My brain is going to die tonight without it :)
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
japruim@xxxxxxxxxx
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php