Forum Moderators: coopster
$query = mysql_query("SELECT `ID`,`FIRST_NAME`,`LAST_NAME`FROM `patients`ORDER BY `LAST_NAME` ASC")
or die (mysql_error());
echo "<select name='name'>\n";
echo "<option value='' selected></option>\n";
while ($data = mysql_fetch_array($query, MYSQL_ASSOC))
{
echo " <option value='{$data['ID']}'>{$data['LAST_NAME']},
{$data['FIRST_NAME']}</option>\n";
}
echo "</select>\n";
And here is the code on the confirmation:
$name = $_POST['name'];
echo $name;
To get the LAST_NAME you need to look the ID up again in your DB, or perhaps save these results in a temporary file if it was a very big query?
OR you could incorporate the LAST_NAME as part of the VALUE attribute? ie:
<option value="ID-LASTNAME">LASTNAME</option>
When the form gets returned you can explode() [uk2.php.net] the value into its two parts:
$patient = explode('-',$_POST['name']);
$id = $patient[0];
$lastname = $patient[1];
if the user selected Smith, Bob that would return Bob Smith for the POST value