0

I'm trying to showing query results in a template.

This is First Select.

<select name="subject" class="form-control" id="search1">
  <option > select 1 </option>
    <?php
      foreach( $rs_sub->result() as $rows ) {
             echo "<option value='$rows->sub_id;'>"; 
             echo $rows->sub_name; 
             echo "</option>";
     } ?>
</select>

And This is Second Select.

<select name="chapter" class="form-control" id="search2">
  <option > select 2 </option>
    <?php
      foreach( $rs_chap->result() as $rows ) {
             echo "<option value='$rows->chap_id;'>"; 
             echo $rows->chap_name; 
             echo "</option>";
     } ?>
</select>

My problem is the Second Select is depend on First Selected's value but in my code , Second Select is show everything and I don't know how to make the condition right.

This is how is work in my opinion, but I don't know how to send the parameter from the template back to php application.

SELECT cht_name FROM ers_chapters
RIGHT JOIN ers_subjects ON ers_chapters.cht_sub_id = $sub_id
GROUP BY cht_name
tereško
  • 58,060
  • 25
  • 98
  • 150
  • You need use Javascript so when first combo change you perform a server call and populate the second combo with the response. – Juan Carlos Oropeza May 22 '18 at 19:54
  • You can check this [fiddle](https://dotnetfiddle.net/1bPZym) of course use C# instead of php but you can see the JQuery calls. – Juan Carlos Oropeza May 22 '18 at 20:12
  • Possible duplicate of [Feed select options from DB depending on another select options](https://stackoverflow.com/questions/18247953/feed-select-options-from-db-depending-on-another-select-options) – alpadev May 23 '18 at 06:41

0 Answers0