populate pulldownbox from query [message #174051] |
Fri, 20 May 2011 18:30 |
Co
Messages: 75 Registered: May 2011
Karma:
|
Member |
|
|
Hi All,
I am having trouble populating a pulldownbox with records from a table
in mySQL database.
I have a table with personnel records.
One of the fields is partner which holds a numeric value pointing to
the id of another record.
I am trying to get the value of the currently selected person's
partner.
for example:
id=1 name=John partner=2
id=2 name=Jane partner=1
With the code I use I do get the pulldownbox filled but it doesn't
display the name right partner info in the box.
$query="SELECT id, firstname, lastname, rank FROM myMembers WHERE id
<> $id ORDER BY lastname";
$result = mysql_query ($query);
echo "<select name=partner class=formFields id=partner
value=''>Partner</option>";
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[rank] $nt[firstname] $nt[lastname]</
option>";
/* Option values are added by looping through the array */
}
echo "<option value=$partner>$nt[rank] $nt[firstname] $nt[lastname]</
option>";
echo "</select>";// Closing of list box
?>
Can anyone help me here?
Regards
Marco
|
|
|