Re: Better way (if...elseif...else)
| From: | Stephan Ahonen | Date: | Fri, 30 Mar 2001 01:20:19 +0000 |
| Subject: | Re: Better way (if...elseif...else) | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-46207@lists.php.net to get a copy of this message | ||
> $val = array("000","050","100");
> $val_name = array("Low","Medium","High");
> $count = count($val);
> $counter = 0;
> while ($counter < $count)
> {
> if ($val[$counter] == $priority)
> {
> $selected = " selected";
> }
> echo "<option
> value=\"$val[$counter]\"$selected>$val_name[$counter]</option>";
> $counter++;
> }
Not quite... You need to reset $selected so that you don't end up with them
all being selected when $priority="000". It's a pretty clever idea, though.
I've rearranged stuff a bit to make it look prettier, and to match the
original functionality closer. Nothing personal, but I can't stand it when
people use while for stuff that looks prettier as a for. =)
$val = array("000","050","100");
$val_name = array("High","Medium","Low");
$fcol_name = array("high","med","low");
$count = count($val);
for ($counter = 0; $counter < $count; $counter++) {
$selected = "";
if ($val[$counter] == $priority) {
$selected = " selected";
$fcol = fcol_name[$counter];
} //if
$pstr .= "<option
value=\"$val[$counter]\"$selected>$val_name[$counter]</option>\r\n";
} //while
Sig for a Day
Stephan Ahonen, ICQ 491101
"That's very funny Scotty, now beam down my clothes!"
Come back tomorrow for a different sig!
Backspace a single "s" to reply by email