Page 1 of 1

Drop down select using PHP

Posted: Tue Sep 02, 2008 1:30 am
by basudeb
Hi
ALL

This is a code.....given below

<select name="year" >
<option value="1">2001</option>
<option value="2">2002</option>
<option value="3">2003</option>
<option value="4">2004</option>
<option value="5">2005</option>
<option value="6">2006</option>
<option value="7">2007</option>
</select>

I need a suggestion using PHP code that will select 2001 ,or 2002 not 1, 2 as value when i will select the dropdown..
Thanks

Basudeb

Re: Drop down select using PHP

Posted: Tue Sep 02, 2008 1:46 am
by greyhoundcode
Well you could simply change the value attribute to suit (value="2001" etc) or you could hold the alternate values in an array:

Code: Select all

$yearValues = array(1 => 2001, 2002, 2003, 2004, 2005);
Ensuring that the index starts at one. Personally, I would go for the former method over the latter.