RE: [PHP] Better way (if...elseif...else)
| From: | Jason Lotito | Date: | Fri, 30 Mar 2001 04:41:24 +0000 |
| Subject: | RE: [PHP] Better way (if...elseif...else) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-46211@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Stephan Ahonen [mailto:analogy@wheezebucket.com]
> Sent: Thursday, March 29, 2001 5:20 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] Better way (if...elseif...else)
>
>
> > $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.
>
Yeah, someone mentioned that after I posted it, then I took a shotgun to my
foot..haha. Yeah, well, hey, I release that code as a Beta Version anyways!
=)
Yes, good ole' for, though I have been so inundated with while() that it
just comes naturally. Hey, at least I don't printf() people to death!
=)
> 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