Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assume that you have a select box that lists all the academies available:</p> <pre><code>&lt;select name="academy" id="acadaemy"&gt; &lt;option value="1"&gt;Academy1&lt;/option&gt; ............................. ............................. &lt;option value="15"&gt;Academy15&lt;/option&gt; &lt;/select&gt; </code></pre> <p>Then you can bind an onchange event for this select to display the desired courses.</p> <pre><code> $('#acadaemy').on('change', function() { var option = this.value; $.ajax({ type: "POST", url: "getCourses.php", data: { 'ac_id': option }, success: function (data) { $('#course_catalog').html(data); } }); }); </code></pre> <p>And in ur getCourses.php</p> <pre><code>Step 1: fetch the POST value (here $_POST['ac_id']) and validate it Step 2: Get all courses. Step 3: Get all courses with specified academy id Step 4: Iterate result from step 3 and create each select tag. Step 5: Iterate result from Step 2 and create option tags and set selected. Step 6: Echo back the result. &lt;?php $id = $_POST['ac_id']; //Do something here to validate the post data $course_query = $db_con-&gt;prepare("SELECT course_id, course_name FROM courses_selection_list;"); $course_query-&gt;execute(); $data = $course_query-&gt;fetchAll();//All courses here $db_select = $db_con-&gt;prepare(" SELECT academy_id, course_name, course_id, course_start_date, course_end_date FROM courses_by_academy WHERE academy_id = :id "); $resultStr = ''; if (!$db_select) return false; if (!$db_select-&gt;execute(array(':id' =&gt; $id))) return false; $results = $db_select-&gt;fetchAll(\PDO::FETCH_ASSOC); // academy specific courses here if (empty($results)) return false; foreach ($results as $value) { // iterate academy courses $resultStr .= '&lt;div class="course"&gt;'; $resultStr .= '&lt;select name="coursename[]" class="course_list"&gt;'; foreach ($data as $row){ // iterate all courses $result .= "&lt;option value='".$row["course_id"].":".$row["course_name"]."'"; if ($result['course_id'] == $row['course_id']) { $resultStr .= " selected='selected'"; } $resultStr .= "&gt;". $row['course_name'] ."&lt;/option&gt;"; } $resultStr .= '&lt;/select&gt;'; $resultStr .= '&lt;/div&gt;'; } echo $resultStr; exit(); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload