title: Populate dropdown list based on selection in another dropdown
body: <p>First of all I would like to say that there are many questions like this one and this is a duplicated question but I tried to do it by myself by looking at other codes but I gave up after 1 hour. </p>
  
  <p>What I want to do is to populate dropdown list based on selection in another dropdown but both dropdown's options are coming from database.</p>
  
  <p>I don't know jQuery and I also saw that some people used onChange function to do what I needed to do.</p>
  
  <p>So, I would like to explain my problem. I have 2 dropdown. One of them is containing the school names and other one contains the course codes. What I need to do is, I want to show course codes based on the school you choose. Because every school has its own courses.</p>
  
  <p>This is the first dropdown. foreach loop may look confusing. I simply echo options but if user selected school already, I echo user's school as selected. That's why I have if else statement there.</p>
  
  <pre><code>$query_schools = "SELECT * FROM SCHOOLS ORDER BY SCHOOL_TYPE ASC";
  $query_users = "SELECT USER_SCHOOL FROM USERS WHERE USER_ID = $user1_id";
  
  $schools_result = mysqli_query($dbConnection, $query_schools);
  $users_result = mysqli_query($dbConnection, $query_users);
  
  while($data = mysqli_fetch_assoc($users_result)){ $user_school = $data['USER_SCHOOL']; }
  
  foreach($schools_result as $school_result){
      if($user_school == $school_result['SCHOOL_NAME']){
          echo "&lt;option value='$school_result[SCHOOL_SHORT_NAME]' selected&gt;$school_result[SCHOOL_NAME]&lt;/option&gt;";
      }else{
          echo "&lt;option value='$school_result[SCHOOL_SHORT_NAME]'&gt;$school_result[SCHOOL_NAME]&lt;/option&gt;";
      }
  }
  </code></pre>
  
  <p>This is the second drop down and they are similar.</p>
  
  <pre><code>$query_programs = "SELECT * FROM PROGRAMS ORDER BY PROGRAM_CODE ASC";
  $query_users = "SELECT USER_PROGRAM FROM USERS WHERE USER_ID = $user1_id";
  
  $programs_result = mysqli_query($dbConnection, $query_programs);
  $users_result = mysqli_query($dbConnection, $query_users);
  
  while($data = mysqli_fetch_assoc($users_result)){ $user_program = $data['USER_PROGRAM']; }
  
  foreach($programs_result as $program_result){
      if($user_program == $program_result['PROGRAM_CODE']){
          echo "&lt;option value='$program_result[PROGRAM_CODE]' title='$program_result[PROGRAM_NAME]' selected&gt;$program_result[PROGRAM_CODE]&lt;/option&gt;";
      }else{
          echo "&lt;option value='$program_result[PROGRAM_CODE]'&gt;$program_result[PROGRAM_CODE]&lt;/option&gt;";
      }
  }
  </code></pre>
  
  <p>if it was pure php, I chould do like this for the first query:</p>
  
  <pre><code>$query_programs = "SELECT * FROM PROGRAMS WHERE PROGRAM_SCHOOL = '$user_school' ORDER BY PROGRAM_CODE ASC";
  </code></pre>
  
  <p>Thank you for your help.</p>