Hi,
I was wondering if someone can help me out with the script below as i am a newbie and have spend several days trying to figure out . My issue is that i can’t seem to find where i would be able to change the text orientation and size of the calculate result as right now it always display the result to left side of screen. Any would be really appreciated. Thanks
Below is the code and a link to the screenshot.
[php]
<?php session_start(); $firsttext="Your Body Mass Index (BMI) is %%BMI%%"; ?> .calculator_div { font-size:11px; font-family:verdana, arial, sans-serif; border:none; padding:25px; margin-top:0px; margin-bottom:0px; margin-right:220px; margin-left:220px; width:400px; } .calculator_div label { display:block; float:left; width:300px; } <?php if(!empty($_POST['calculator_ok'])) { // set vars in session foreach($_POST as $key=>$var) { $_SESSION['bmi_calc_'.$key]=$var; } if($_POST['system']=='english') { $height=$_POST['height_ft_en']*12+$_POST['height_in_en']; $bmi=($_POST['weight_en']*703) / ($height*$height); } else { $height=$_POST['height_met']/100; $bmi=$_POST['weight_met'] / round(($height*$height),2); } $bmi=number_format($bmi,1,".",""); // prepare message for the user if($bmi<=18.5) { $bmimsg="Underweight"; } if($bmi>18.5 and $bmi<=24.9) { $bmimsg="Normal"; } if($bmi>=25 and $bmi<=29.9) { $bmimsg="Overweight"; } if($bmi>=30) { $bmimsg="Obese"; } // what is the weight range? if($bmimsg!='Normal') { if($_POST['system']=='english') { $lowerlimit=number_format(( 18.5 * ($height*$height) ) / 703); $lowerlimitkg=number_format($lowerlimit*0.453,1,".",""); $upperlimit=number_format(( 24.9 * ($height*$height) ) / 703); $upperlimitkg=number_format($upperlimit*0.453,1,".",""); } else { $lowerlimit=number_format( 18.5 * ($height*$height) * 2.204 ); $lowerlimitkg=number_format(18.5 * ($height*$height),1,".",""); $upperlimit=number_format( 24.9 * ($height*$height) * 2.204 ); $upperlimitkg=number_format(24.9 * ($height*$height),1,".",""); } } //prepare texts $firsttext=str_replace("%%BMI%%",$bmi,$firsttext); $firsttext=str_replace("%%BMIMSG%%",$bmimsg,$firsttext); $lowertext=str_replace("%%LOWERLIMIT%%",$lowerlimit,$lowertext); $lowertext=str_replace("%%LOWERLIMITKG%%",$lowerlimitkg,$lowertext); $lowertext=str_replace("%%UPPERLIMIT%%",$upperlimit,$lowertext); $lowertext=str_replace("%%UPPERLIMITKG%%",$upperlimitkg,$lowertext); $uppertext=str_replace("%%LOWERLIMIT%%",$lowerlimit,$uppertext); $uppertext=str_replace("%%LOWERLIMITKG%%",$lowerlimitkg,$uppertext); $uppertext=str_replace("%%UPPERLIMIT%%",$upperlimit,$uppertext); $uppertext=str_replace("%%UPPERLIMITKG%%",$upperlimitkg,$uppertext); } ?><form method="post">
<div class="calculator_div">
<div><input type="radio" value="english" name="system" <?php if($_SESSION['bmi_calc_system']=="" or $_SESSION['bmi_calc_system']=='english') echo "checked='true'";?> onclick="changeSystem('english');"> Imperial
<input type="radio" value="metric" name="system" <?php if($_SESSION['bmi_calc_system']!='' and $_SESSION['bmi_calc_system']=='metric') echo "checked='true'";?> onclick="changeSystem('metric');"> Metric
</div>
<div><label>Your Weight:</label>
<span id="englishWeight" style="display:<?php echo ($_SESSION['bmi_calc_system']=='' or $_SESSION['bmi_calc_system']=='english')?'block':'none'?>;"><input type="text" name="weight_en" size="6" value="<?php echo !empty($_SESSION['bmi_calc_weight_en'])?$_SESSION['bmi_calc_weight_en']:""?>"> lbs</span>
<span id="metricWeight" style="display:<?php echo (($_SESSION['bmi_calc_system']=="" or $_SESSION['bmi_calc_system']=='english'))?'none':'block'?>;"><input type="text" name="weight_met" size="6" value="<?php echo !empty($_SESSION['bmi_calc_weight_met'])?$_SESSION['bmi_calc_weight_met']:""?>"> kg</span>
</div>
<div><label>Your Height:</label>
<span id="englishHeight" style="display:<?php echo (($_SESSION['bmi_calc_system']=='' or $_SESSION['bmi_calc_system']=='english'))?'block':'none'?>;"><input type="text" size="6" name="height_ft_en" value="<?php echo !empty($_SESSION['bmi_calc_height_ft_en'])?$_SESSION['bmi_calc_height_ft_en']:""?>"> ft
<input type="text" size="6" name="height_in_en" value="<?php echo ($_SESSION['bmi_calc_height_in_en']!='')?$_SESSION['bmi_calc_height_in_en']:""?>"> in</span>
<span id="metricHeight" style="display:<?php echo ($_SESSION['bmi_calc_system']=='' or $_SESSION['bmi_calc_system']=='english')?'none':'block'?>;">
<input type="text" name="height_met" size="6" value="<?php echo ($_SESSION['bmi_calc_height_met']!='')?$_SESSION['bmi_calc_height_met']:""?>"> cm
</span>
</div>
<div align="left">
<input type="hidden" name="calculator_ok" value="ok">
<input type="submit" value="Calculate Your BMI">
</div>
</div>
</form>
<?php if(!empty($_POST['calculator_ok'])):?>
<?=$firsttext?>
<?php switch($bmimsg) { case 'Normal': // you can echo here if you want for normal weight people break; case 'Underweight':
echo $lowertext;
break;
default:
echo $uppertext;
break;
}
?>
<p align="center"><a href="http://<?=$_SERVER['HTTP_HOST'];?><?=$_SERVER['REQUEST_URI']?>">Calculate again</a></p>
[/php]