|
Posted by strawberry on 03/31/06 15:16
Here's how I do it...
The form:
echo "<select name='student'>\n";
echo "<option value=''>Select...\n";
while ($row = mysql_fetch_array ($students,MYSQL_ASSOC))
{
echo "<option value={$row['student_id']}>{$row['f_name']}
{$row['l_name']}\n";
}
echo "</select>\n";
The query that populates this list goes something like this. Apologies
for any errors:
//Get a list of all students (e.g. student_id,f_name,l_name) and order
them by last name.
//Put records with no last name at the bottom of the list.
$query = "SELECT * ,
IF(l_name IS NULL or l_name='', 1, 0)
AS isnull
FROM students
ORDER BY isnull ASC, l_name ASC;";
$students = mysql_query($query) or die ("Couldn't gather a list of
students!!!");
The trick is simply passing the student_id to the 'option value'
statement.
HTH
[Back to original message]
|