PHP Classes

Date (Year) Select

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  Locating addresses on...  >  All threads  >  Date (Year) Select  >  (Un) Subscribe thread alerts  
Subject:Date (Year) Select
Summary:Creating long Select List of Years
Messages:3
Author:Albert Padley
Date:2006-12-29 21:43:27
Update:2006-12-29 23:16:25
 

  1. Date (Year) Select   Reply   Report abuse  
Picture of Albert Padley Albert Padley - 2006-12-29 21:43:27
I need to create a long list of years in a Select. I really don't wan't to have to do this by hand. I have tried the following, but keep getting an invalid options array error.

$my_date=date("Y");
$first_year = $my_date-3;
$yearEnd=$my_date;

$inter_date = "array(";
//$inter .= "\"\"=>\"--\",";

for($year=$first_year; $year <= $yearEnd; $year++) {
$inter_date .= "\"$year\"=>\"$year\",";
}
$inter_date .= ")";

The above appears to create the array. Then I do the following:

$accident->AddInput(array(
"TYPE"=>"select",
"NAME"=>"year",
"ID"=>"year",
"VALUE"=>"2003",
"SELECTED"=>"2003",
"SIZE"=>1,
"OPTIONS"=>$inter_date,
));

What am I doing wrong or how can this be done in another way?

Thanks.

  2. Re: Date (Year) Select   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-12-29 22:09:39 - In reply to message 1 from Albert Padley
No, you are not creating an array but rather a string with PHP code to define an array.

Your code would work better like this:

$my_date=date("Y");
$first_year = $my_date-3;
$yearEnd=$my_date;

$inter_date = array(
// ""=>"--"
);

for($year=$first_year; $year <= $yearEnd; $year++) {
$inter_date[$year]=$year
}

  3. Re: Date (Year) Select   Reply   Report abuse  
Picture of Albert Padley Albert Padley - 2006-12-29 23:16:25 - In reply to message 2 from Manuel Lemos
Yes, thank you. That does work quite well.