RE: [PHP] Better way (if...elseif...else)
| From: | Grimes, Dean | Date: | Fri, 30 Mar 2001 13:16:51 +0000 |
| Subject: | RE: [PHP] Better way (if...elseif...else) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-46305@lists.php.net to get a copy of this message | ||
$fcol = ($priority == "000") ? "high" : (($prioridy == "050") ?
"med" :
"low");
$pstr .= sprintf( "<option value=\"000\" %s>High\n".
"<option value=\"050\" %s>Medium\n".
"<option value=\"100\" %s>Low\n",
($priority == "000") ? "selected" : "",
($priority == "050") ? "selected" : "",
($priority == "100") ? "selected" : "");
That should do the trick!!
Dean
-----Original Message-----
From: Ashley M. Kirchner [mailto:ashley@pcraft.com]
Sent: Thursday, March 29, 2001 3: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.
AMK4
--
W |
| I haven't lost my mind; it's backed up on tape somewhere.
|____________________________________________________________________
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ashley M. Kirchner <mailto:ashley@pcraft.com> .
303.442.6410 x130
SysAdmin / Websmith . 800.441.3873 x130
Photo Craft Laboratories, Inc. . eFax 248.671.0909
http://www.pcraft.com . 3550 Arapahoe
Ave #6
.................. . . . . Boulder, CO 80303, USA
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net