Q:

Populate list item elements based on dropdown list choice

I have a course management php page with a database connected in the backend with courses, modules, and modules in a specific course. 
I have a form with a dropdown list with options to select a course. Underneath I would like a list of modules in the chosen course from the dropdown list above to show as list item elements. My php code for the form is below. How would I do this using php?
    <form method="post" action="courseManagement.php">
                    <table>
                    <center> <span>Course Management<span></center><P><P><P>
                    <tr>
                    <td>Choose course to add module:     </td>
                         <td> <?php
                            $sql = "SELECT courseName FROM course";
                            $result = mysql_query($sql);
                            echo "<select name='courseName'>";
                                while ($row = mysql_fetch_array($result)) {
                                    echo "<option value='" . $row['courseName'] ."'>" . $row['courseName'] ."</option>";
                                    }
                                    echo "</select>";
                        ?> 
                    </td>

                        </tr>

                        <tr>
                        <td>
                        Modules in the choosen course
                        </td>
                        <td>

                        <li>Projects and management</li>
                        <li>Programming 2</li>
                        <li>Business Analysis</li>

                        </td>
                    </tr>

                    <tr>
                    <td>Choose module to add to course: </td>
                         <td> <?php
                            $sql = "SELECT moduleName FROM module";
                            $result = mysql_query($sql);
                            echo "<select name='moduleName'>";
                                while ($row = mysql_fetch_array($result)) {
                                    echo "<option value='" . $row['moduleName'] ."'>" . $row['moduleName'] ."</option>";
                                    }
                                    echo "</select>";
                        ?> 
                    </td>
                </tr>

                <tr>
                    <td>Choose module to delete from the course: </td>
                         <td> <?php
                            $sql = "SELECT moduleName FROM module";
                            $result = mysql_query($sql);
                            echo "<select name='moduleName'>";
                                while ($row = mysql_fetch_array($result)) {
                                    echo "<option value='" . $row['moduleName'] ."'>" . $row['moduleName'] ."</option>";
                                    }
                                    echo "</select>";
                        ?> 
                    </td>
                </tr>

                </table><p><br>

                <center>    
                <input type="submit" value="Update">
                </center>
                </form> 

A:

If you can call ajax it's very simple to use this code:
SELECT * FROM course;

Your dropdown code is something like this:  
<select name="course" id="course">
   <option value='1'>English</option>
   <option value='2'>Gujarati</option>
</select>

Then you want to selectable course by module display in second dropdown, so you can use this in jQuery:
$(document).ready(function() { 
$('#course').change(function(){
        var courseid = $(this).val();
        if(courseid != '' && $.isNumeric(courseid)){
            $.post('path of file',{id:courseid}, function(result){
                // usable code //
            }); 
        }
    });
});

Then this query write in which file are you call.
id = $this->input->post('id');

SQL:
 SELECT module.*,course.* 
 FROM course 
 LEFT JOIN module ON course.moduleId = module.Id 
 WHERE course.moduleId = id;

You can call this query using ajax call, and you get all list of module by courseid.

