On Fri, 24 Sep 2004 13:39:53 +0100, Geoff Berrow
<blthecat@ckdog.co.uk> wrote:
[color=blue]
>I noticed that Message-ID:
><29cee28.0409210102.620134bb@posting.google.com> from harryman100
>contained the following:
>[color=green]
>>$string = "";
>>foreach ($months AS $key => $month) {
>> $string .= "<option value=\"$key\">$month</option>\n";
>>}[/color]
>
>Slick, but I prefer this (untested)..
>
>
>$string = "<select name="month">";
>foreach ($months AS $key => $month) {
> if($key==$k){$selected="selected";} else{$selected="";}
> $string .= "<option value=\"$key\" $selected>$month</option>\n";
>}
>$string.="</select>";[/color]
Is one str_replace faster than 12 if's? If so, then:
$string = "<select name="month">";
foreach ($months AS $key => $month) {
$string .= "<option value=\"$key\" $selected>$month</option>\n";
}
$string.="</select>";
if(isset($_POST['month']) {
$k=$_POST['month'];
$string = str_replace("\$k\">","\"$k\" selected>", $string);
}
--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one!
http://signup.databasix.com
================================================== =========================