> -----Original Message-----
> From: Stephan Ahonen [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, March 29, 2001 5:20 PM
> To: [EMAIL PROTECTED]
> 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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to