"Ashley M. Kirchner" wrote:
Is there a better way to write the following snippet:
if ($priority == "000") {
$fcol="high";
$pstr .= "option value=\"000\" selectedHigh\n";
$pstr .= "option value=\"050\"Medium\n";
$pstr .= "option value=\"100\"Low\n";
$fcol = ($priority == "000") ? "high" : (($prioridy == "050") ? "med" :
"low");
$pstr .= sprintf( "option value=\"000\" %sHigh\n".
"option value=\"050\" %sMedium\n".
"option value=\"100\" %sLow\n",
($priority == "000")
on...
Andr Nss
-Original Message-
From: Grimes, Dean [mailto:[EMAIL PROTECTED]]
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 == &
$p_arr=array("000","050","100");
$fc_arr=array("high","med","low");
$ptext_arr("High","Medium","Low");
for($x=0;$xcount($p_arr);$x++)
{ $pstr.="option value=\"$p_arr[$x]\" ";
if($priority==$p_arr[$x])
{
$pstr.="selected";
$fcol=$fc_arr[$x];
}
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
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:
Is
-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:
if ($priority == "000") {
-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.
OoPs! Yes, reset $selected, haha
$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";
-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"
10 matches
Mail list logo