part one:
populating the dropdown
<?
//include the db connection file
require("dbconn.php");
//set the sql statement to select all the data in the table
$sql="select * from mytable";
//execute the query
$result=mysql_query($sql,$link) or die ("Can't connect to db");
//build the select box
echo "<select name=\'myfield\'>";
//set a counter to make the first record the selected one
$x=1;
//if the query suceeded print the results
if (!$result){
while $rows=mysql_fetch_array($result){
if ($x==1){
//fill the options in the select box - note the single quotes
//around the value--- for the [b]selected[/b] value
echo "<option value='".$rows['thefield']."' SELECTED>".$rows['thefield']."</option>";
//increase the counter to cause the rest just to be options
$x++;
}elseif ($x<>1){ //item is option selected?
//fill the options in the select box - note the single quotes
//around the value
echo "<option value='".$rows['thefield']."'>".$rows['thefield']."</option>";
}else{ //else statement for the no results loop
echo "There are no results";
} //end if statement
//close select box
echo "</select>";
?>
part 2:
do the same with the item selected coming from another table/query
you will need to do another query here to get the selected values from the users previously input data
code is very similar, so:
<?
//include the db connection file
require("dbconn.php");
//get the user defined data item for the select list
$sql1="select item from user_data_table where userid =$userid";
$user_result=mysql_query($sql1, $link) or die ("Can' t connect");
//get the item from the db - note only one item selected
$item = mysql_fetch_row($user_result)
//set the sql statement to select all the data in the table
$sql="select * from mytable";
//execute the query
$result=mysql_query($sql,$link) or die ("Can't connect to db");
//build the select box
echo "<select name=\'myfield\'>";
//if the query suceeded print the results
if (!$result){
while $rows=mysql_fetch_array($result){
if ($item==$rows['thefield']){
//fill the options in the select box - note the single quotes
//around the value--- for the [b]selected[/b] value
echo "<option value='".$rows['thefield']."' SELECTED>".$rows['thefield']."</option>";
}else{ //item and option not the same
//fill the options in the select box - note the single quotes
//around the value
echo "<option value='".$rows['thefield']."'>".$rows['thefield']."</option>";
}else{ //else statement for the no results loop
echo "There are no results";
} //end if statement
//close select box
echo "</select>";
?>
note code not tested...
hth