Re: Stuck... Long day I think.. ;-)

From: Date: Fri, 16 May 2003 23:19:42 +0000
Subject: Re: Stuck... Long day I think.. ;-)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147993@lists.php.net to get a copy of this message
> I do the same thing here and it works fine: > > for($i = 250; $i <= 1000; $i += 250) { > $c_val[] = $i; > } . . . > I'm not seeing the difference in terms of functionality. One big difference is your protein routine deals with decimals (floating point) and your calories routine deals with whole numbers (integers). One general rule of thumb is never to test a floating point number for equality. > I can not get ($v != $_POST['protein']) to evaluate as > true. I would think it would *always* evaluate as true (i.e. always != ). Is that what you meant to say? Regards, --Frappy On Friday 16 May 2003 06:46 pm, Brian V Bonini wrote: > for($i = 1; $i <= 2.1; $i += 0.1) { > $p_val[] = $i; > } > echo "Protien (pr/kg/bodyweight):\n"; > echo '<select name="protein">'."\n"; > foreach($p_val as $v) { > $str = ($v != $_POST['protein']) ? "<option > value=\"$v\">" . sprintf("%.1f", $v) . "g</option>" > : > "<option value=\"$v\" selected=\"selected\">" . > sprintf("%.1f", $v) . "g</option>"; echo $str ."\n"; > } > echo "</select>\n"; > > I can not get ($v != $_POST['protein']) to evaluate as > true. > > print_r() says > > Array > ( > [0] => 1 > [1] => 1.1 > [2] => 1.2 > [3] => 1.3 > [4] => 1.4 > [5] => 1.5 > [6] => 1.6 > [7] => 1.7 > [8] => 1.8 > [9] => 1.9 > [10] => 2 > ) > > I AM selecting a value and echo $_POST['protein']; > returns the correct value. > > > I do the same thing here and it works fine: > > for($i = 250; $i <= 1000; $i += 250) { > $c_val[] = $i; > } > echo "Select Calories (number of cals used per hour while > training):\n"; echo '<select name="r_calories">'."\n"; > foreach($c_val as $v) { > $string = ($v != $_POST['r_calories']) ? "<option > value=\"$v\">$v</option>" : "<option value=\"$v\" > selected=\"selected\">$v</option>"; echo $string . "\n"; > } > echo "</select>\n"; > > I'm not seeing the difference in terms of functionality.

« previous php.general (#147993) next »