Stuck... Long day I think.. ;-)
| From: | Brian V Bonini | Date: | Fri, 16 May 2003 22:46:18 +0000 |
| Subject: | Stuck... Long day I think.. ;-) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-147991@lists.php.net to get a copy of this message | ||
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.