Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date field help

Status
Not open for further replies.

george123456724

Technical User
Feb 26, 2002
6
GB
Hi,

I must stress I don't know *anything* about PHP coding!

I am using a PHP MySQL interface. The date field is split into selection lists for date (00 to 31), month (00 to 12) and year (currently 2002 to 2005). I want to change the code to allow me to choose between 2002, 2003, 2004, 2005 and also 0000 - giving the option of an unspecified year in my database.

The code in the php script for generating the year selection box is shown below. The values for start_year and end_year are obtained from a config.php file, which I can easily edit.

Can anyone tell me how I can change the script to get non-sequential values into this selection box as explained above?

_________________

for ($i=$start_year; $i<=$end_year; $i++){
$year_select .= &quot;<option value=\&quot;$i\&quot;&quot;;
if($year != &quot;&quot; and $year == $i){
$year_select .= &quot; selected&quot;;
} // end if
$year_select .= &quot;>$i</option>&quot;;
} // end for

__________________

Many thanks

George
 
Do &quot;view source&quot; in your browser and you will se something like this:

<form>
...
<select>
<option value=2002 selected>2002
<option value=2003>2003
</option>
...

You need to write out a line

<option value=0000>no year specified

before the </option>

for ($i=$start_year; $i<=$end_year; $i++){
$year_select .= &quot;<option value=\&quot;$i\&quot;&quot;;
if($year != &quot;&quot; and $year == $i){
$year_select .= &quot; selected&quot;;
} // end if
$year_select .= &quot;><option value=0000>No year selected&quot;;
$year_select .= &quot;$i</option>&quot;;
} // end for
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top