View Single Post
Old 03-20-2009, 08:09 AM   #3 (permalink)
sdsinc
Missing in action
 
sdsinc's Avatar
 
Name: Kate
Last Online: Yesterday 04:42 PM
iTrader: (41)
Join Date: Jul 2005
Posts: 4,679
DNF$: 28,133
Location: .cz
Country:


Here is one example.

The idea is that when the form loads, you retrieve their saved data from the DB. Let's just fetch their year of birth as an example.
Then you build your combo using a loop (here current year = 2009 through 1909). The year that matches your variable gets the selected attribute.

PHP Code:
<?php
$link
=mysql_pconnect("localhost","user","password");
mysql_select_db("db",$link);
$result mysql_query("select date_format(birth_date,'%Y') as birth_year from members where member_id=1");

$row=mysql_fetch_array($result); // fetch first row
$year=$row["birth_year"]; // retrieve 4-digit year of birth

// display combo: current year -> -100
$current_year=date("Y");
echo 
'<select name="cbo_year">';
for (
$i $current_year$i >= ($current_year-100); $i--) {
echo 
'<option '.($year == $i ' selected ' '').' value="'.$i.'" >'.$i.'</option>';
}
echo 
'</select>';
?>
For XHTML compliant code use this instead
PHP Code:
echo '<option '.($year == $i ' selected="selected " ' '').' value="'.$i.'" >'.$i.'</option>'
__________________
VeryOldNames.com
sdsinc is offline   Reply With Quote