Reputation: 735
I have a dropdown selection box to generate another select box based on the selection of the first box. I have put an example below.
<form action="" method="type">
<select name="Semester">
<option value="Fall2013">Fall 2013</option>
<option value="Spring2013">Spring 2013</option>
</select>
I would like to put the classes that the student is enrolled in for the selected semester in a select box so then I can have them enter homework for the selected class. I would like to keep it as simple as possible as I am just learning MySQL/PHP. The semesters and classes will be pulled from a MySQL database based on what user is logged in.
Upvotes: 1
Views: 168
Reputation: 2109
I would use jQuery and AJAX to get the classes based on the selection in the first drop down. Here is a tutorial on how to accomplish it:
http://phpcodeforbeginner.blogspot.com/2013/01/jquery-ajax-tutorial-and-example-of.html
Edit: A simpler approach (from a programmer's standpoint, not the end-user's standpoint) would be do just use PHP and do a step/page approach. i.e. user makes a selection on step/page 1 and submits the form to page 2. Step/page 2 then uses PHP to query the database and get the classes to display to the user.
Upvotes: 0
Reputation: 16495
suppose $row
array that is fetched by your mysql query, now what you would do is...
<form action="" method="type">
<select name="Semester">
<?php foreach($row as $uniqe) { ?>
<option value="<?php echo $unique ?> "> <?php echo $unique ?> </option>
<?php } ?>
</select>
So, the above code Will generate all data stored in $row
one by one
Upvotes: 1