title: Changing value of selectbox on change event of another select box from database in codeigniter
body: <p>I have a view file as</p>
  
  <pre><code>&lt;select name="tournaments" id ="tournaments" class="form-control"&gt;
  &lt;?php foreach ($tournaments as $tournament): ?&gt;
  &lt;option value="&lt;?php echo $tournament-&gt;TournamentID ?&gt;"&gt;&lt;?php echo $tournament-&gt;TournamentName ?&gt;&lt;/option&gt;
  &lt;?php endforeach ?&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>A script</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function(){
          var initial_target_html = '&lt;option value=""&gt;Please select a Tournament...&lt;/option&gt;'; //Initial prompt for target select
          $('#matches').html(initial_target_html);
          $("#tournaments").change(function(e){
              e.preventDefault();
              var data = ($("#tournaments").val());
              $('#matches').html('&lt;option value=""&gt;Loading...&lt;/option&gt;');
               $.ajax({
                  type:"POST",
                  dataType: 'json',
                  url:"&lt;?php echo base_url('admin/dashboard/update_match_box') ?&gt;",
                  data: {tournament:data},
                 success: function(data) {
  
                  }
              });
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Controller function is</p>
  
  <pre><code>public function update_match_box()
  {
      $sql = "Some query"
      $query = $this-&gt;db-&gt;query($sql);
      $json= $query-&gt;result();
      $this-&gt;output-&gt;set_content_type('application/json')
          -&gt;set_output(json_encode($json));
  }
  </code></pre>
  
  <p>Controller file is going to return multiple rows, which I need to capture in success event of ajax and update second select box accordingly, how am I suppose to do that?</p>