manhattanpaul Posted February 14, 2008 Share Posted February 14, 2008 Hi all I have this page which collects some information on our clients. As part of this assessment, it collects their height and weight. I want to get this to automatically calculate their BMI (which is calculated by Weight / Height Squared. Here is my coding - you will see the Height and Weight Variables. What should I do to get the BMI to calcualte automatically or with the press of a button ?? Thanks Paul <?php $type=$_GET['type']; if ($type=='') { ?> <a href='index.php?page=interventions&type=add'>Add new intervention</a><br> <br> <table border=1><tr><th width='140'>Client Name</th><th>Intervention Date</th><th width='140'>Options</th></tr><? $result=mysql_query("SELECT * FROM interventions ORDER BY year DESC, month DESC, day DESC"); while ($row=mysql_fetch_array($result)) { echo "<tr><td>"; $clientid=$row['clientid']; $clientarray=mysql_fetch_array(mysql_query("SELECT * FROM clients WHERE id='$clientid'")); echo $clientarray['name']; echo "</td><td>"; $day=$row['day']; if ($day==01) { echo "1st"; } elseif ($day==02) { echo "2nd"; } elseif ($day==03) { echo "3rd"; } elseif ($day==04) { echo "4th"; } elseif ($day==05) { echo "5th"; } elseif ($day==06) { echo "6th"; } elseif ($day==07) { echo "7th"; } elseif ($day==08) { echo "8th"; } elseif ($day==09) { echo "9th"; } elseif ($day==21) { echo "21st"; } elseif ($day==22) { echo "22nd"; } elseif ($day==23) { echo "23rd"; } elseif ($day==31) { echo "31st"; } else { echo $day; echo "th"; } echo " "; $monthid=$row['month']; $montharray=mysql_fetch_array(mysql_query("SELECT * FROM months WHERE id='$monthid'")); echo $montharray['month']; echo " "; echo $row['year']; echo "</td><td><a href='index.php?page=interventions&type=add&interid=".$row['id']."'>Update Intervention</a><br> <a href='index.php?page=delete&type=interventions&id=".$row['id']."'>Delete Intervention</a></tr>"; } echo "</table>"; } elseif ($type=='add') { $interid=$_GET['interid']; echo "Please fill in the following form to add a new intervention.<br><br><table border=1> <form name='form1' action='index.php?page=interventions&type=add2' method='post'>"; if ($interid=='') { echo "<input type='hidden' name='interid' value='NEW'>"; } else { echo "<input type='hidden' name='interid' value='$interid'>"; $client=mysql_fetch_array(mysql_query("SELECT * FROM interventions WHERE id='$interid'")); } echo "<tr><td> Client Name</td><td>"; echo " <select name='clientid'><option></option>"; $res1=mysql_query("SELECT * FROM clients ORDER BY name ASC, dobyear DESC, dobmonth DESC, dobday DESC"); while ($r=mysql_fetch_array($res1)) { echo "<option value='".$r['id']."' "; if ($client['clientid']==$r['id']) { echo "selected"; } echo ">".$r['name']." (".$r['dobday']."/".$r['dobmonth']."/".$r['dobyear'].")</option>"; } echo "</select>"; echo "</td></tr>"; echo "<tr><td>Intervention Date</td><td><select name='day'><option></option>"; $times=32; $x=1; while ($x<$times) { echo "<option "; if ($client['day']==$x) { echo "selected"; } echo ">"; if ($x<10) { echo "0"; } echo $x; echo "</option>"; $x++; } echo "</select>"; echo " <select name='month'><option></option>"; $res1=mysql_query("SELECT * FROM months"); while ($r=mysql_fetch_array($res1)) { echo "<option value='".$r['id']."' "; if ($client['month']==$r['id']) { echo "selected"; } echo ">".$r['month']."</option>"; } echo "</select>"; echo "<select name='year'>"; $times=2020; $x=2008; while ($x<$times) { echo "<option "; if ($client['year']==$x) { echo "selected"; } echo ">".$x."</option>"; $x++; } echo "</select>"; echo "</td></tr>"; echo "<tr><td>Venue</td><td>"; echo " <select name='venueid'><option></option>"; $res1=mysql_query("SELECT * FROM venues WHERE 1"); while ($r=mysql_fetch_array($res1)) { echo "<option value='".$r['id']."' "; if ($client['venueid']==$r['id']) { echo "selected"; } echo ">".$r['name']."</option>"; } echo "</select>"; echo "</td></tr>"; echo "<tr><td>Staff Member Involved</td><td>"; $staffhold=$client['staffid']; echo " <select name='staffid'><option></option>"; $res1=mysql_query("SELECT * FROM staff WHERE 1"); while ($r=mysql_fetch_array($res1)) { echo "<option value='".$r['id']."' "; if ($staffhold==$r['id']) { echo "selected"; } echo ">".$r['name']."</option>"; } echo "</select>"; echo "</td></tr>"; echo "<tr><td>Improvements since last visit</td><td><textarea name='improvements' rows='6' cols='50'>".$client['improvements']."</textarea></td></tr>"; echo "<tr><td>Risk Assessment Used</td><td>"; echo " <select name='assessment'><option></option>"; $res1=mysql_query("SELECT * FROM assessment"); while ($r=mysql_fetch_array($res1)) { echo "<option value='".$r['id']."' "; if ($client['assessment']==$r['id']) { echo "selected"; } echo ">".$r['assessment']."</option>"; } echo "</select>"; echo "</td></tr>"; echo "<tr><td>Review Of Risk Score</td><td>"; echo " <select name='review'><option></option>"; $res1=mysql_query("SELECT * FROM review"); while ($r=mysql_fetch_array($res1)) { echo "<option class='".$r['id']."' value='".$r['id']."' "; if ($client['review']==$r['id']) { echo "selected"; } echo ">".$r['name']."</option>"; } echo "</select>"; echo "(before any improvements made)</td></tr>"; echo "<tr><td>Advice Offered and Improvements Suggested</td><td><textarea name='actions' rows='6' cols='50'>".$client['actions']."</textarea></td></tr>"; echo "<tr><td>BP Reading (Systolic)</td><td><input type='text' name='BPSystolic' size='5' value='".$client['BPSystolic']."'></td></tr>"; echo "<tr><td>BP Reading (Diastolic)</td><td><input type='text' name='BPDiastolic' size='5' value='".$client['BPDiastolic']."'></td></tr>"; echo "<tr><td>Height</td><td><input type='text' name='Height' size='15' value='".$client['Height']."'> Enter This as XX.x m</td></tr>"; echo "<tr><td>Weight</td><td><input type='text' name='Weight' size='15' value='".$client['Weight']."'> Enter this as XX.x Kg</td></tr>"; echo "<tr><td>BMI</td><td><input type='text' name='BMI' size='15' value='".$client['BMI']."'> This is calculated by Weight (in Kg) / Height Squared (in m) </td></tr>"; echo "<tr><td>Referral agencies suggested</td><td><table spacing='0' padding='0'><tr><th width='280'></th><th>Yes</th><th width='5'></th><th>No</th></tr>"; $times=18; $x=1; $background=1; while ($x<$times) { $array=mysql_fetch_array(mysql_query("SELECT * FROM referral WHERE id='$x'")); echo "<tr><td class='"; echo $background; echo "'>"; echo $array['name']; echo "</td><td class='"; echo $background; echo "'><input type='radio' name='$x' value='Yes' "; if ($client["{$x}"]=='Yes') { echo "checked"; } echo "> </td><td class='"; echo $background; echo "'></td><td class='"; echo $background; echo "'> <input type='radio' name='$x' value='No' "; if ($client["{$x}"]=='No' || $client["{$x}"]=='') { echo "checked"; } echo "> </td></tr>"; $background++; if ($background==3) { $background=1; } $x++; } echo "</table><br><br>Other (please specify)<input type='text' name='referral' size='40' value='".$client['referral']."'></td></tr>"; echo "<tr><td>Letter Sent To GP</td><td><input name='gpletter' type='checkbox' value='Yes' "; if ($client['gpletter']=='Yes') { echo "checked"; } echo ">"; echo "</table>"; echo "<br><br><input type='submit' name='submit' value='"; if ($interid=='') { echo "Add New Intervention"; } else { echo "Update Intervention"; } echo "'>"; echo "</form>"; } elseif ($type=='add2') { $interid=$_POST['interid']; $clientid=$_POST['clientid']; $venueid=$_POST['venueid']; $staffid=$_POST['staffid']; $BPSystolic=$_POST['BPSystolic']; $BPDiastolic=$_POST['BPDiastolic']; $Weight=$_POST['Weight']; $Hieght=$_POST['Height']; $BMI=$_POST['BMI']; $improvements=$_POST['improvements']; $assessment=$_POST['assessment']; $review=$_POST['review']; $actions=$_POST['actions']; $referral=$_POST['referral']; $gpletter=$_POST['gpletter']; $day=$_POST['day']; $month=$_POST['month']; $year=$_POST['year']; $i1=$_POST['1']; $i2=$_POST['2']; $i3=$_POST['3']; $i4=$_POST['4']; $i5=$_POST['5']; $i6=$_POST['6']; $i7=$_POST['7']; $i8=$_POST['8']; $i9=$_POST['9']; $i10=$_POST['10']; $i11=$_POST['11']; $i12=$_POST['12']; $i13=$_POST['13']; $i14=$_POST['14']; $i15=$_POST['15']; $i16=$_POST['16']; $i17=$_POST['17']; if ($interid=='NEW') { mysql_query("INSERT INTO interventions (clientid, venueid, staffid, improvements, assessment, BPDiastolic, BPSystolic, Height, Weight, BMI, review, actions, referral, gpletter, day, month, year,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`10`,`11`,`12`,`13`,`14`,`15`,`16`,`17`) VALUES ('$clientid', '$venueid', '$staffid', '$improvements', '$assessment', '$BPDiastolic', '$BPSystolic', '$Height', '$Weight', '$Weight', '$review', '$actions', '$referral', '$gpletter', '$day', '$month', '$year','$i1','$i2','$i3','$i4','$i5','$i6','$i7','$i8','$i9','$i10','$i11','$i12','$i13','$i14','$i15','$i16','$i17')"); echo "New intervention succesfully added. Click <a href='index.php'>HERE</a> to continue"; } else { mysql_query("UPDATE interventions SET clientid='$clientid', venueid='$venueid', staffid='$staffid', improvements='$improvements', BPDiastolic='$BPDiastolic', BPSystolic='$BPSystolic', Height='$Height', Weight='$Weight', BMI='$BMI', assessment='$assessment', review='$review', actions='$actions', referral='$referral', gpletter='$gpletter', day='$day', month='$month', year='$year',`1`='$i1',`2`='$i2',`3`='$i3',`4`='$i4',`5`='$i5',`6`='$i6',`7`='$i7',`8`='$i8',`9`='$i9',`10`='$i10', `11`='$i11',`12`='$i12',`13`='$i13',`14`='$i14',`15`='$i15',`16`='$i16',`17`='$i17' WHERE id='$interid'"); echo "Existing intervention successfully updated. Click <a href='index.php'>HERE</a> to continue"; } } ?> mod edit: Use code tags <?php // your code ?> and just post the relevant code if you expect people to read it Link to comment https://forums.phpfreaks.com/topic/91157-bmi-calculations/ Share on other sites More sharing options...
Barand Posted February 14, 2008 Share Posted February 14, 2008 basically <?php if (isset($_GET['sub'])) { $wt = $_GET['wt']; $ht = $_GET['ht']; echo "BMI = " . number_format($wt/($ht*$ht), 2); } ?> <form> Weight <input type="text" name="wt" size="5"> kgm<br/> Height <input type="text" name="ht" size="5"> m.<br/> <input type="submit" name="sub" value="Get BMI"> </form> Link to comment https://forums.phpfreaks.com/topic/91157-bmi-calculations/#findComment-467215 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.