php-general | 2001032
Date: 03/29/01
- Next message: Philip Olson: "Re: [PHP] PHP and .htaccess"
- Previous message: Les Neste: "[PHP] PHP and .htaccess"
- In reply to: Ashley M. Kirchner: "[PHP] Better way (if...elseif...else)"
- Next in thread: Morgan Curley: "RE: [PHP] Better way (if...elseif...else)"
- Reply: Morgan Curley: "RE: [PHP] Better way (if...elseif...else)"
- Reply: Stephan Ahonen: "Re: [PHP] Better way (if...elseif...else)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> -----Original Message-----
> From: Ashley M. Kirchner [mailto:ashley <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") {
> $fcol="high";
> $pstr .= "<option value=\"000\" selected>High\n";
> $pstr .= "<option value=\"050\">Medium\n";
> $pstr .= "<option value=\"100\">Low\n";
> } elseif ($priority == "050") {
> $fcol="med";
> $pstr .= "<option value=\"000\">High\n";
> $pstr .= "<option value=\"050\" selected>Medium\n";
> $pstr .= "<option value=\"100\">Low\n";
> } else {
> $fcol="low";
> $pstr .= "<option value=\"000\">High\n";
> $pstr .= "<option value=\"050\">Medium\n";
> $pstr .= "<option value=\"100\" selected>Low\n";
> }
>
> I just hate having to repeat pieces of code. This piece here just
> generates a drop down list of items, with the current one being the
> selected one.
$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++;
}
-- 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>
- Next message: Philip Olson: "Re: [PHP] PHP and .htaccess"
- Previous message: Les Neste: "[PHP] PHP and .htaccess"
- In reply to: Ashley M. Kirchner: "[PHP] Better way (if...elseif...else)"
- Next in thread: Morgan Curley: "RE: [PHP] Better way (if...elseif...else)"
- Reply: Morgan Curley: "RE: [PHP] Better way (if...elseif...else)"
- Reply: Stephan Ahonen: "Re: [PHP] Better way (if...elseif...else)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

