Drop down select using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
basudeb
Forum Commoner
Posts: 44
Joined: Wed Dec 20, 2006 12:13 am

Drop down select using PHP

Post 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
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Drop down select using PHP

Post 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.
Post Reply