|
|
|
|
|
|
| |
| <?php
/*
Description: Waist-to-Hip Ratio Calculator
Author: Murray Moffatt for A Web 4 U Designs
Notes: Originally written for use on CarolynGibson.com
History:
2003-04-?? : Initial coding.
2005-02-13 : Remove extra CarolynGibson.com HTML and make
stand-alone for publishing on WeberDev.com.
2005-02-16 : Get $step from $_POST and add a Go Back link.
*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Waist-to-Hip Ratio</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="author" content="A Web 4 U Designs - www.aweb4u.co.nz">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h3>Waist-to-Hip Ratio (WHR)</h3>
<?php
$step = $_POST["step"];
if ($step == "") {
?>
<p>The scales do not necessarily tell you the true story of your weight.
They do not indicate the distribution of your fat storage onto the abdomen
and central region of your body. When it comes to your health it isn't
only a matter of what you weigh but where you are storing the excess fat
cells.</p>
<p>To establish whether your weight is placing your health at risk you can
do a risk assessment test. Use the on-line calculator below to take the
test.</p>
<p>Do you want to work in metric (centimetres and kilograms) or imperial
(inches and pounds)? </p>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" name="unitsForm" id="unitsForm">
<table border="0" cellspacing="1" cellpadding="2">
<tr>
<td><input name="units" type="radio" value="metric" checked>
Metric</td>
</tr>
<tr>
<td><input type="radio" name="units" value="imperial">
Imperial</td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Next ->">
<input name="step" type="hidden" id="step" value="1">
</td>
</tr>
</table>
</form>
<?php
}
if ($step == "1") {
$units = $_POST["units"];
?>
<p>Measure your waist at the smallest circumference and type it in the
box below:</p>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" name="inputForm" id="inputForm">
<table border="0" cellspacing="1" cellpadding="2">
<tr>
<td><b>Your waist measurement:</b></td>
<td align="left"><input name="waist" type="text" id="waist" size="6" maxlength="6">
<?php if ($units == "metric") echo " cm"; else echo " inches"; ?>
</td>
</tr>
<tr>
<td><input name="step" type="hidden" id="step" value="2">
<input name="units" type="hidden" id="units" value="<?php echo $units; ?>">
</td>
<td align="left"><input type="submit" name="Submit" value="Next ->">
</td>
</tr>
</table>
</form>
<?php
}
if ($step == "2") {
$units = $_POST["units"];
$waist = $_POST["waist"];
if (!IsValidNumber($waist, ".", 2, 1, 999)) {
echo "<p>The waist measurement you entered, \"$waist\", is invalid.<br>";
echo "Please enter a number between 1 and 999, optionally with up to two decimal places.<br>";
echo "For example <b>90.5</b> is 90 and a half, <b>105.25</b> is 105 and a quarter.</p>";
echo "<p>Please press Back on your browser and try again.</p>";
die("</body></html>");
}
$highrisk = FALSE;
if ($units == "metric") {
if ($waist >= 88) $highrisk = TRUE;
}
if ($units == "imperial") {
if ($waist >= 35) $highrisk = TRUE;
}
if ($highrisk) {
?>
<p>Your waist measurement is equal to or greater than 88 cm (35 inches);
you are considered to be in the <b>high-risk</b> category and need to
lose weight.</p>
<?php
}
?>
<p>Type your hip measurement into the box below:</p>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" name="inputForm" id="inputForm">
<table border="0" cellspacing="1" cellpadding="2">
<tr>
<td align="right"><b>Your hip measurement:</b></td>
<td align="left"><input name="hip" type="text" id="hip" size="6" maxlength="6">
<?php if ($units == "metric") echo " cm"; else echo " inches"; ?>
</td>
</tr>
<tr>
<td><input name="step" type="hidden" id="step" value="3">
<input name="units" type="hidden" id="units" value="<?php echo $units; ?>">
<input name="waist" type="hidden" id="waist" value="<?php echo $waist; ?>">
</td>
<td align="left"><input type="submit" name="Submit" value="Next ->">
</td>
</tr>
</table>
</form>
<?php
}
if ($step == "3") {
$units = $_POST["units"];
$waist = $_POST["waist"];
$hip = $_POST["hip"];
if (!IsValidNumber($waist, ".", 2, 1, 999)) {
echo "<p>The waist measurement you entered, \"$waist\", is invalid.<br>";
echo "Please enter a number between 1 and 999, optionally with up to two decimal places.<br>";
echo "For example <b>90.5</b> is 90 and a half, <b>105.25</b> is 105 and a quarter.</p>";
echo "<p>Please press Back on your browser and try again.</p>";
die("</body></html>");
}
if (!IsValidNumber($hip, ".", 2, 1, 9999)) {
echo "<p>The hip measurement you entered, \"$hip\", is invalid.<br>";
echo "Please enter a number between 1 and 999, optionally with up to two decimal places.<br>";
echo "For example <b>90.5</b> is 90 and a half, <b>105.25</b> is 105 and a quarter.</p>";
echo "<p>Please press Back on your browser and try again.</p>";
die("</body></html>");
}
$ratio = round(($waist / $hip), 2);
?>
<p>Your Waist-to-Hip Ratio is <b><?php echo $ratio; ?></b></p>
<p>For women an answer of 0.8 or higher indicates an increased health risk
and weight loss is required.</p>
<p>For men an answer of 0.9 or higher indicates an increased health risk
and weight loss is required.</p>
<p>Your Waist-to-Hip Ratio of <?php echo $ratio; ?> indicates that
<?php
if ($ratio >= 0.8) {
echo " your health is at risk.";
} else {
echo " your health is ok.";
}
?>
<p><a href="<?php echo $_SERVER["PHP_SELF"]; ?>">Go Back</a></p>
<?php
}
function IsValidNumber($number, $decimal = null, $dec_prec = null, $min = null, $max = null){
if (is_array($number)) {
extract($number);
}
$dec_prec = $dec_prec ? "{1,$dec_prec}" : '+';
$dec_regex = $decimal ? "[$decimal][0-9]$dec_prec" : '';
if (!preg_match("|^[-+]?\s*[0-9]+($dec_regex)?\$|", $number)) {
return false;
}
if ($decimal != '.') {
$number = strtr($number, $decimal, '.');
}
$number = (float)$number;
if ($min !== null && $min > $number) {
return false;
}
if ($max !== null && $max < $number) {
return false;
}
return true;
}
?>
</body>
</html> | | |
|
| Calculate Body Mass Index Categories : PHP, Algorithms, Regexps | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | | | This script is a contact form between users of a
website (kinda like the PM function on the forums)
Categories : PHP, Databases, MySQL, Regexps | | | Simple way to replace a variable value in a .conf (.ini) file using a
webbrowser - the first stage of a complete universal configuration editor Categories : PHP, Regexps, Code Editors, Filesystem | | | ereg -- Regular expression match Categories : PHP, PHP Functions, Regexps | | | Gets the browser and OS from the $_SERVER['http_user_agent'] variable in PHP Categories : PHP, HTTP, Regexps | | | Boolean Keyword Interpreter Categories : PHP, Algorithms, Search Engines | | | a PHP Function to Get only the filename (remove the extension) using regular expressions. Categories : PHP, Regexps, Beginner Guides | | | PHP Script to find url links in a page Categories : PHP, URLs, Regexps, Arrays | | | I need a trim function/regexp that will trim all " " from the ends of a string. Categories : Regexps, PHP, Strings | | | Diffusion-Limited Aggregation visualization Categories : PHP, Graphics, Algorithms, Math. | | | Check for functional file links (broken Files)
Categories : PHP, Data Validation, FTP, Regexps, Arrays | | | Browse a MySQL database & draw a tree view & load final items into a template page. Categories : MySQL, Complete Programs, Algorithms, PHP, Databases | |
|
|
|