> $p_arr=array("000","050","100");
> $fc_arr=array("high","med","low");
> $ptext_arr("High","Medium","Low");
> for($x=0;$x { $pstr.=" if($priority==$p_arr[$x])
> {
> $pstr.="selected";
> $fcol=$fc_arr[$x];
> }
> $pstr.=">$ptext_arr[$x]\n";
> }
Even better! This l
gt; Sent: 30. mars 2001 15:17
> To: 'Ashley M. Kirchner'; PHP-General List
> Subject: RE: [PHP] Better way (if...elseif...else)
>
>
> $fcol = ($priority == "000") ? "high" : (($prioridy == "050")
> ? "med" :
> "low&qu
priority == "000") ? "selected" : "",
($priority == "050") ? "selected" : "",
($priority == "100") ? "selected" : "");
That should do the trick!!
Dean
-Original
"Ashley M. Kirchner" wrote:
>
> Is there a better way to write the following snippet:
>
> if ($priority == "000") {
> $fcol="high";
> $pstr .= "High\n";
> $pstr .= "Medium\n";
> $pstr .= "Low\n";
> } elseif ($priority == "050") {
> $fcol="med";
>
> -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 = 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 " value=\"$val[$counter]\"$selected>$val_name[$counter]";
> $counter++
> -Original Message-
> From: Morgan Curley [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, March 29, 2001 2:52 PM
> To: PHP-General List
> Subject: RE: [PHP] Better way (if...elseif...else)
>
>
> Make sure you reset $selected at the end of the while loop.
>
ito wrote:
> > -Original Message-
> > From: Ashley M. Kirchner [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, March 29, 2001 1:56 PM
> > To: PHP-General List
> > Subject: [PHP] Better way (if...elseif...else)
> >
> >
> >
> > Is th
> -Original Message-
> From: Ashley M. Kirchner [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, March 29, 2001 1:56 PM
> To: PHP-General List
> Subject: [PHP] Better way (if...elseif...else)
>
>
>
> Is there a better way to write the following snippet:
&g
you can use switch statements:
switch($priority){
case 000:
code here
break;
case med:
more code
break;
default:
in case none match use default
}
-jack
"Ashley M. Kirchner" wrote:
>
> I
One thing I would do different is:
switch ($fcol){
case 000:
break;
case 050:
break;
default:
break;
}
To me the switch/case code is easier to read/maintain.
I know that doesn't actually solve your repetition problem but it will make
it a little easier to look at.
John Guynn
This email
Is there a better way to write the following snippet:
if ($priority == "000") {
$fcol="high";
$pstr .= "High\n";
$pstr .= "Medium\n";
$pstr .= "Low\n";
} elseif ($priority == "050") {
$fcol="med";
$pstr .= "High\n";
$pstr .= "Medium\n";
12 matches
Mail list logo