/    Sign up×
Community /Pin to ProfileBookmark

can’t get it right

I keep on getting a 0 result for the following script. I suspect is the order of my if..else, but I am so tired I can’t find the answer. Any suggestions?

<? php

if ($gender == “female”){
$uppername = strtoupper($name);
$k1 = .9;
$k2 = 24;

if ($lbsorkg == “kg”){
$var1 = $mass;}
else if ($lbsorkg == “lbs”){
$var1 = $weight;
$mass = $weight /(2.20);}

{
if ($fat == “1”) {$fatnumber = 1.0; $fatrange = “10-14 %”;}
else if ($fat == “2”){$fatnumber = .95; $fatrange = “14-20 %”;}
else if ($fat == “3”){$fatnumber = .90; $fatrange = “20-28 %”;}
else if ($fat == “4”){$fatnumber = .85; $fatrange = “>28 %”;}
}
$bmr= $mass * $k1* $k2 * $fatnumber;
$roundbmr= round($bmr);
}

else{
$uppername = strtoupper($name);
$k1 = 1;
$k2 = 24;
if ($lbsorkg == “kg”){
$var1 = $mass;}
else if ($lbsorkg == “lbs”){
$var1 = $weight;
$mass = $weight /(2.20);}

{
if ($fat == “1”) {$fatnumber = 1.0; $fatrange = “10-14 %”;}
else if ($fat == “2”){$fatnumber = .95; $fatrange = “14-20 %”;}
else if ($fat == “3”){$fatnumber = .90; $fatrange = “20-28 %”;}
else if ($fat == “4”){$fatnumber = .85; $fatrange = “>28 %”;}
}
$bmr= $mass * $k1* $k2 * $fatnumber;
$roundbmr= round($bmr);
}
?>

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@christopherauthorJan 20.2004 — okay, I forgot to say that at the end you write:

<? echo "$roundbmr"; ?> for an answer of 0!
Copy linkTweet thisAlerts:
@crh3675Jan 23.2004 — In your code:

<? php

if ($gender == "female"){

$uppername = strtoupper($name);

$k1 = .9;

$k2 = 24;

if ($lbsorkg == "kg"){

$var1 = $mass;}

else if ($lbsorkg == "lbs"){

$var1 = $weight;

$mass = $weight /(2.20);}


You attribute $var1=$mass. "$mass" is undefined. It should be:

if ($lbsorkg == "kg"){

$var1 = $weight;}

else if ($lbsorkg == "lbs"){

$var1 = $weight/(2.20);}

Also, $var1 is not used in your calculation. Your final calculation should be:

$bmr= $var1 * $k1* $k2 * $fatnumber;
Copy linkTweet thisAlerts:
@christopherauthorJan 24.2004 — I defined mass in my form, which I forgot to include, the form looks like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>

<title>Estimated BMR-NaturalMuscleGirl.net</title>

<link rel="stylesheet" href="http://naturalmusclegirl.net/calculators/CSS/01.css" type="text/css">

<!--Script created for use in MuscleGirl.Org subdivisions:NaturalMuscleGirl.Net, NaturalMuscleGirl.Com, MuscleGirl.Net and Muscle-Exchange.Com-->

<style type="text/css">

<!--

table {font-family:Verdana, Arial;font-size:10pt;}

-->

</style>

</head>

<body leftmargin="0" topmargin="0">

<form method="post" action="bmr2.php">

<table border="0" cellpadding="5" cellspacing="0" width="100%" >

<tr><td colspan="4" width=""><p style="line-height:1.3;text-align:justify">Calculate your

<i>adjusted</i> Basic or Basal Metabolic Rate (BMR) based on your percent

bodyfat and bodymass:</p></td></tr>

<tr><td colspan="4" width=""><b>estimated bmr</b> = bodymass x gendermultiple x

fatmultiple x constant</td></tr>


<tr><td colspan="4" height="50" width="100%">&nbsp;</td></tr>

<tr>

<td colspan="1" width="20%"><b>NAME</b></td>

<td colspan="3" width="80%"><input type="text" size="21" maxlength="25" name="name" /></td>

</tr>

<tr>

<td width="30%"><b>WEIGHT (lbs) or MASS (kg)</b></td>

<td width="80%">

<input type="text" size="5" maxlength="3" name="var1" />

<select name="lbsorkg">

<option selected="selected" value="select" />Select One</option>

<option value="lbs" >lbs</option>

<option value="kg" >kg</option>

</select>

</td>

</tr>

<tr>

<td colspan="1" width=""><b>SEX</b></td>

<td colspan="3" width="">

<select name="gender">

<option selected="selected" value="select" />Select One</option>

<option value="female" >Female</option>

<option value="male" >Male</option>

</select>

</td>

</tr>

<tr>

<td colspan="1"><b>BODYFAT</b></td>

<td colspan="4">

<select name="fat" >

<option selected="selected" value="select" />Select One</option>

<option value="1" />Women 14-18% or Men 10-14%</option>

<option value="2" />Women 18-28% or Men 14-20%</option>

<option value="3" />Women 28-38% or Men 20-28%</option>

<option value="4" />Women >38% or Men >28%</option>

</select>

</td>

</tr>

<tr><td colspan="4" height="50" width="100%">&nbsp;</td></tr>

<tr>

<td colspan="4" align=center width="100%">

<input type="submit" name="submit" value="Calculate" size="20"></td>

</tr>

</table>

</form>

</body>

</html>
Copy linkTweet thisAlerts:
@crh3675Jan 25.2004 — If you are passing $var1 , then you can't reassign it like this:

$var1 = $weight;

because $weight equals nothing, $var1 holds the value you want. I think you need to reverse that to :

$weight=$var1;

and

$mass=$var1;

--Craig
×

Success!

Help @christopher spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...