title: Select based on another select using php
body: <p>I have one <code>select option</code> which is based on another <code>select option</code>.</p>
  
  <p>Meaning,
  If Option: <strong>One</strong> is selected from the first option then the second option should have Options: <strong>S1, F1</strong>.</p>
  
  <p>If Option: <strong>Two</strong> is selected from the first option then the second option should have Options: <strong>S2, F2</strong>.</p>
  
  <p>And So on..</p>
  
  <p>But my <strong>second</strong> <code>select option</code> is having all the options.</p>
  
  <p><strong>Note: Options in select are based on the database.</strong></p>
  
  <p>I tried:</p>
  
  <pre><code>&lt;td&gt;&lt;select class="country" name="item1"&gt;
    &lt;option value="Select Item"&gt;Item&lt;/option&gt;
    &lt;?php
    $stmt = $user_home-&gt;runQuery('SELECT * FROM item ORDER BY Sr ASC ');
      $stmt-&gt;execute();
  
      if($stmt-&gt;rowCount() &gt; 0)
      {
  
          while($row=$stmt-&gt;fetch(PDO::FETCH_ASSOC))
          {
              extract($row);
              ?&gt;
    &lt;option value="&lt;?php echo $IRN ?&gt;"&gt;&lt;?php echo $Name; ?&gt;&lt;/option&gt;
    &lt;?php
          }
      }
  
          ?&gt;
  &lt;/select&gt;&lt;/td&gt;
  
        &lt;td&gt;&lt;select class="country" name="service1"&gt;
    &lt;option value="Select Service"&gt;Service&lt;/option&gt;
    &lt;?php
    $stmt = $user_home-&gt;runQuery('SELECT * FROM service WHERE IRN = :irn ORDER BY Sr ASC ');
      $stmt-&gt;bindParam(':irn',$IRN);
      $stmt-&gt;execute();
  
      if($stmt-&gt;rowCount() &gt; 0)
      {
  
          while($row=$stmt-&gt;fetch(PDO::FETCH_ASSOC))
          {
              extract($row);
              ?&gt;
    &lt;option value="&lt;?php echo $SRN ?&gt;"&gt;&lt;?php echo $Name; ?&gt;&lt;/option&gt;
    &lt;?php
          }
      }
  
          ?&gt;
  &lt;/select&gt;&lt;/td&gt;
  </code></pre>
  
  <p>Focused Code: </p>
  
  <pre><code>  $stmt = $user_home-&gt;runQuery('SELECT * FROM service WHERE IRN = :irn ORDER BY Sr ASC ');
      $stmt-&gt;bindParam(':irn',$IRN);
      $stmt-&gt;execute();
  </code></pre>
  
  <p><strong>I know how to do this with fixed values (not using database &amp; codding all options), but I am unable to do with dynamic values (using database for options).</strong></p>