nighthawk Posted September 1, 2009 Share Posted September 1, 2009 Hi everyone: I am new to programming and PHP. Need your help in getting a project started. Here's the situation/project: I have created an HTML web page and on that page, I want to have three drop down menus. The first drop down menu has to be populated with "Course Departments". When 'a' Course Department gets selected by a user, it should dynamically populate the second drop down menu with all the Courses that the selected Department offers. When a Course gets selected, it should then populate the third drop down menu with all the sections of the selected course. As soon as the third or last drop down menu gets selected, it should take users to a new page with information about the selected department/course/section combo. It'd be great if that page could be created dynamically based on the selections made by the user. I'd truly appreciate any help/advise you can offer me to get started. I'd also like to have this project divided in two interfaces: [*]An admin interface which is used to add/delete/modify Departments, Courses, and Sections [*]A user interface where users make their selections. Thanks in advance for all your help and advise. Quote Link to comment https://forums.phpfreaks.com/topic/172725-help-me-get-started-with-this/ Share on other sites More sharing options...
kickstart Posted September 1, 2009 Share Posted September 1, 2009 Hi While you drop downs are perfectly possible, the best way to do this would be using AJAX, which I would suggest isn't something to start out with. Best to have a screen containing a form which you submit for the first drop down, then displaying the 2nd and with the result of the first stored in a hidden field. And then the same for the next drop down. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/172725-help-me-get-started-with-this/#findComment-910428 Share on other sites More sharing options...
ignace Posted September 1, 2009 Share Posted September 1, 2009 echo '<h2>Departments</h2>'; $query = 'SELECT * FROM departments'; $result = mysql_query($query); if ($result && mysql_num_rows($result)) {// make sure query succeeded and it contains atleast one row echo '<select name="departements">'; $department = abs(!empty($_POST['departments']) ? (int) $_POST['departments'] : 0); while ($row = mysql_fetch_assoc($result)) { echo '<option value="', $row['departments_id'], '"', $department === $row['departments_id'] ? ' selected="selected"' : '', '>', $row['departments_title'], '</option>'; } echo '</select>'; if ($department) {// a department was selected echo '<h2>Courses</h2>'; $query = 'SELECT * FROM courses JOIN courses_departments ON courses_id = courses_departments_courses_id WHERE courses_departments_departments_id = %d'; $fquery = sprintf($query, $department); $result = mysql_query($fquery); if ($result && mysql_num_rows($result)) { echo '<select name="courses">'; $course = abs(!empty($_POST['courses']) ? (int) $_POST['courses'] : 0); while ($row = mysql_fetch_assoc($result)) { echo '<option value="', $row['courses_id'], '"', $course === $row['courses_id'] ? ' selected="selected"' : '', '>', $row['courses_title'], '</option>'; } echo '</select>'; if ($course) {// a course was selected echo '<h2>Sections</h2>'; $query = 'SELECT * FROM sections JOIN courses_sections ON sections_id = courses_sections_sections_id WHERE courses_sections_courses_id = %d'; $fquery = sprintf($query, $course); $result = mysql_query($fquery); if ($result && mysql_num_rows($result)) { echo '<select name="sections">'; $section = abs(!empty($_POST['sections']) ? (int) $_POST['sections'] : 0); while ($row = mysql_fetch_assoc($result)) { echo '<option value="', $row['sections_id'], '"', $course === $row['sections_id'] ? ' selected="selected"' : '', '>', $row['sections_title'], '</option>'; } echo '</select>'; if ($section) {// a section was selected // send the user to the new page and provide the section id // in section-info.php: // SELECT * FROM sections WHERE sections_id = %d header('Location: section-info.php?id=' . $section); } } } else { echo '<h2>Sections</h2>', '<select name="sections" disabled="disabled"></select>'; } } } else {// no department was yet selected therefor both courses and sections are disabled echo '<h2>Courses</h2>', '<select name="courses" disabled="disabled"></select>', '<h2>Sections</h2>', '<select name="sections" disabled="disabled"></select>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/172725-help-me-get-started-with-this/#findComment-910436 Share on other sites More sharing options...
nighthawk Posted September 1, 2009 Author Share Posted September 1, 2009 Thanks! I have created an HTML file so far that looks like this: <p>Choose Below: </p> <form name="isc" id="isc" action="mycombo.php"> <table align="center" border="0" cellspacing="0" cellpadding="0"> <tr align="center"> <td nowrap="nowrap" height="11"> <select name="Departments" size="1" style="font-size:11px; font-family:Verdana; width: 190px;"> <option selected="selected">Select Your Department</option> <option>DEPT 1</option> <option>DEPT 2</option> <option>DEPT 3</option> <option>DEPT 4</option> <option>DEPT 5</option> <option>DEPT 6</option> <option>DEPT 7</option> <option>DEPT 8</option> <option>DEPT 9</option> <option>DEPT 10</option> </select> <select name="Courses" size="1" style="font-size:11px; font-family:Verdana; width: 190px;"> <option value=" " selected="selected">Select Your Course Number</option> </select> <select name="Sections" size="1" style="font-size:11px; font-family:Verdana; width: 190px;"> <option value=" " selected="selected">Select Your Section</option> </select> </td> </tr> </table> </form> </td> </tr> </table></td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td height="55" align="center" bgcolor="#FFFFFF" class="cop"><!--DWLayoutEmptyCell--> </td> </tr> <tr> <td height="19" align="center" class="bg3" bgcolor="#FFFFFF"> </td> </tr> </table> </td> </tr> </table> Should I create the tables Departments, Courses, Sections in MySQL? Quote Link to comment https://forums.phpfreaks.com/topic/172725-help-me-get-started-with-this/#findComment-910530 Share on other sites More sharing options...
ignace Posted September 2, 2009 Share Posted September 2, 2009 Should I create the tables Departments, Courses, Sections in MySQL? No but in order to provide a complete example I had to make up some tables so you would get a feel for the workflow of my code Quote Link to comment https://forums.phpfreaks.com/topic/172725-help-me-get-started-with-this/#findComment-910799 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.