It's been a while since I've done a 'for' statement...

Here's my new working code:

<?php
for ($i=01;$i<=12;$i++) {
  if($i == date("m")) {
    $selected = " selected";
    }
    else {
      $selected = "";
    }
  print "<option
value=\"".date("m",mktime(0,0,0,$i))."\"$selected>".date("F",mktime(0,0,0,$i
))."</option>\n";
}
?>

I found that you have to put quotes around the date() paramaters (like
date("m") instead of date(m)) or PHP will put an error message in your
error.log file in Apache (2.0.35/php4.2.0). Here's the message:

PHP Notice:  Use of undefined constant m - assumed 'm' in C:\Program
Files\Apache Group\Apache2\htdocs\select.php on line 3

My error log was huge because of this (and the failed first attempt of this
code).

-Dash

-----Original Message-----
From: George Nicolae [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, May 02, 2002 3:19 PM
To: [EMAIL PROTECTED]
Subject: [PHP-WIN] Re: PHP generation of <select> fields


you make two mistakes. let's see the correct code:

for ($i=1;$i<=12;$i++)
{
          if($i == date(m))
//first here ^^^ (must be == not just one "=")
  {
       $selected = " selected";
     }
//here is the second: if $selected ="selected" for $i=4 (may) $i will be
remain selected for all month > then may
//you need the following line to correct this problem.
 else $selected="";
    print "<option
value=\"".date(m,mktime(0,0,0,$i))."\"$selected>".date(F,mktime(0,0,0,$i))."
</option>\n";
  }


--


Best regards,
George Nicolae
IT Manager
___________________
PaginiWeb.com  - Professional Web Design
www.PaginiWeb.com


"Dash McElroy" <[EMAIL PROTECTED]> wrote in message
ABA3F1F1A223D411BE6C006008A6F7E23E6425@MSX1-PTON">news:ABA3F1F1A223D411BE6C006008A6F7E23E6425@MSX1-PTON...
> I am trying to use PHP to generate and automatically select the current
> month in an HTML Form. Here is the code that flails:
>
>   for ($i=01;$i<=12;$i++) {
>     if($i = date(m)) {
>       $selected = " selected";
>     }
>     print "<option
>
value=\"".date(m,mktime(0,0,0,$i))."\"$selected>".date(F,mktime(0,0,0,$i))."
> </option>\n";
>   }
>
> The output is a large amount of April's in the Select dropdown box - my
> machine then goes crazy for a while whilst the hard drive chunks like mad.
>
> Thanks.
>
> -Dash



-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to