title: How can i populate a dropdown list by selecting the value from another dropdown list?
body: <p>I have build two drop downs (like state and city) by fetching the records of both drop downs from mysql database and am trying to build the tool in which, while selecting any value (i.e. any state) from first drop down, at that time in second drop down (in city) only those values (cities) under that value (state) selected in first drop down should be visible. </p>
  
  <p>Here's my code:</p>
  
  <pre><code>&lt;tr&gt;    
          &lt;td id='hed'&gt;&lt;span style="font-family:verdana,geneva,sans-  serif"&gt;State&lt;/state&gt;&lt;/td&gt;
          &lt;td&gt;
          &lt;?php 
          $dbcon = mysql_connect("@ip","@username","@password");
  
          if($dbcon)
          {
              mysql_select_db("@database", $dbcon);
          }
          else
          {
              die('error connecting to the database');
          }
  
          $qry = "select @value(state) from @tablename  ";
          $result = mysql_query($qry) or die(mysql_error());
  
          $dropdown = "&lt;select name='@valuename' id='officeItemList' style='cursor:pointer;cursor:hand;'&gt;";
          while($row = mysql_fetch_array($result))
          {           
              $dropdown .= "\r\n&lt;option value='{$row['@value']}' &gt; {$row['@value']} &lt;/option&gt;";
          }
          $dropdown .= "\r\n&lt;/select&gt;"; 
          echo $dropdown;
          mysql_close($dbcon);
          ?&gt;
          &lt;/td&gt; 
      &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td id='hed'&gt;&lt;span style="font-family:verdana,geneva,sans-serif"&gt;City&lt;/span&gt;&lt;/td&gt;
          &lt;td colspan="1"&gt; 
          &lt;?php 
          $dbcon = mysql_connect("@ip","@username","@password");
  
          if($dbcon)  
          {
              mysql_select_db("@database", $dbcon);
          }  
          else
          {
              die('error connecting to the database');
          }  
  
          $qry = "select value2(city) from @tablename where ";
          $result = mysql_query($qry) or die(mysql_error()); 
  
          $dropdown = "&lt;select name='@value2' id='officeItemList' style='cursor:pointer;cursor:hand;'&gt;";
          while($row = mysql_fetch_array($result)) 
          {
  
              $dropdown .= "\r\n&lt;option value='{$row['@value2']}' &gt; {$row['@value2']} &lt;/option&gt;";
          }
          $dropdown .= "\r\n&lt;/select&gt;"; 
          echo $dropdown;
          mysql_close($dbcon);
          ?&gt;      
  
  
          &lt;/td&gt;
      &lt;/tr&gt;
  </code></pre>