I am writing a page that will allow teachers to view and update their class schedule. The first query ask teachers to input userid and password and then pulls up thier recored based on userid. The record is pulled up in a form so that info can be updated. One of the fields (class name) is a select list that is built using a separate query of a class_list table. I want the form selected option to be the row result from the first query of the staff table and the options to come from the second query course_list.
a snippet of the relevant PHP looks like this:
(NOTE: the variable P1 comes from the staff table and the variable short_name comes for the course_list table.)
$query = "SELECT * FROM staff WHERE userid = '$userid' ORDER BY lname";
$result = mysql_query ($query)
or die ("Cannot execute query");
if (mysql_num_rows ($result) == 0)
die ("No user with userid = '$userid' found");
if (mysql_num_rows ($result) > 1)
die ("More than one user with userid = '$userid' found");?>
<form METHOD="post" ACTION="<?=$PHP_SELF?>?action=2">
<? $row = mysql_fetch_array ($result);?>
...
<tr>
<td align="center" class="medgray">1</td>
<td><input type="text" name="p1_loc" size="8" value="<?=$row[p1_loc]?>" class="smallblack"></td>
<td><select name="p1" class="smallblack">
<option selected><?=$row[p1]?></option>
<?
$sql = "select short_name from course_list order by short_name";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
?>
<option><?=$row[short_name]?></option>
<? }
?>
</select></td>
</tr>