I'm new to Joomla and PHP. I'm still learning a lot of stuff and was hoping to get some help.
I'd like to add a BMI (Body Mass Index) calculator to my site. The formula is very easy, it's weight (kg) / height (m) ^2.
I've gone through the steps of the Hello World module maker to figure out how to add the php code to the site. But I'm running into problems and I'd like to get some help.
Code: Select all
<?php
/**
* @version 1.0 $
* @package BMI
* @copyright (C) 2007 Me
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/
/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
?>
<form action="<?php echo sefRelToAbs( 'index.php?option=com_content&task=view&id=919' ); ?>" method="post">
<table summary="bmi" border="0" cellpadding="8" cellspacing="8" height="155" width="144">
<tbody>
<tr>
<td>
<p>
Height (cm):
</p>
</td>
<td><input name="height" size="2" type="text" /></td>
</tr>
<tr>
<td>
<p>
Weight (kg):
</p>
</td>
<td><input name="weight" size="2" type="text" /></td>
</tr>
<tr>
<td colspan="2" align="center">
<input value="Submit" type="submit" /><br />
</td>
</tr>
</tbody>
</table>
</form>
<?php
$weight = $_POST['weight'] ;
$height = $_POST['height'] ;
?>
<?php
if ($height > 1) {
$heightm = $height / 100 ;
$bmi = $weight / ($heightm * $heightm);
$bmi = sprintf("%01.1f", $bmi);
}
?>
My BMI is: <?php if ($height > 1) { echo " $bmi " ; } ?>
Alternatively, it'd be great if there was a way to get the BMI number to appear in the static content page explaining the BMI.