Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2001032

RE: [PHP] Better way (if...elseif...else) From: Jason Lotito (Jason <email protected>)
Date: 03/29/01

> -----Original Message-----
> From: Stephan Ahonen [mailto:analogy <email protected>]
> Sent: Thursday, March 29, 2001 5:20 PM
> To: php-general <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: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>