Jobs search - VeraciTek, Inc. - We Build Websites - Find jobs - Free online video sharing India - Find jobs

PDA

View Full Version : retrieving data into a drop down menu...


alhen
Oct 12th 2007, 2:02 pm
Hi,
I can get my data from the mysql database into a drop down menu ok, but it always shows what's chosen, then the entire list below it. Like this:

(if the menu is to choose a year)


<select name="ud_year" tabindex="190" id="year">
<option value="<? echo $year;?>" selected><? echo $year;?></option>
<option value="2007" selected>2007</option>
<option value="2008" selected>2008</option>
<option value="2009" selected>2009</option>
<option value="2010" selected>2010</option>
</select>

But if the year already stored in the data base is, for example, 2009 - the menu will display like this when you drop it down:

2009
2007
2008
2009
2010

with two 2009's.

is there a way for it to pull 2009 from mysql, but just have it show 2009 in the list, in place?

I hope this makes sense, please let me know if you need clarification.

Thanks! ~Alex

tamen
Oct 12th 2007, 2:30 pm
<select name="ud_year" tabindex="190" id="year">
<option value="2007"<? if ($year == 2007) echo " selected"; ?>>2007</option>
<option value="2008"<? if ($year == 2008) echo " selected"; ?>>2008</option>
<option value="2009"<? if ($year == 2009) echo " selected"; ?>>2009</option>
<option value="2010"<? if ($year == 2010) echo " selected"; ?>>2010</option>
</select>