I have scoured the web for the answer to this question. I am a nubie to PHP so the answer may be simple I just don’t see it.
I’m trying to dynamically create two drop down menus from the results of one query. Sounds simple enough but I want to have my php execute most of the work above and then just plug in my values into my html below. Here is my example so far.
<?php
$form_query = "SELECT `class_name`, `instructor` FROM `schedule`";
$form_fetch = mysql_query($form_query);
while ($result = mysql_fetch_array($form_fetch)) {
$class = $result[0];
$class_options = "<option value='$class'>" . $class . " </option>";
$instructor = $result[1];
$instructor_options = "<option value='$instructor'>" . $instructor . " </option>";
}
?>
<h1>Add New Class or Workshop</h1>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
Select Class Name:
<select name="instructor">
<option>Select Class Name</option>
<?php echo $class_options;?>
</select>
Select Instructor Name:
<select name="instructor">
<option>Select Instructor Name</option>
<?php echo $instructor_options;?>
</select>
</form>
This is only giving me the last result from each column. How can I get all of the results form the column class name into the drop down for the Class Names and all the results from the column instructors into the Instructors drop down menu?
Any help would be greatly appreciated :)