title: mysql select distinct query in PHP
body: <pre><code>$sql = "SELECT DISTINCT Branch FROM student_main";
      $result = mysql_query($sql);
      $row_num = mysql_num_rows($result);
      $rows = mysql_fetch_array($result);
      echo "&lt;select name='Branch'&gt;";
      for($i=0;$i&lt;=$row_num-1;$i++){
          echo "&lt;option value='".$rows[$i]."'&gt;".$rows[$i]."&lt;/option&gt;";
  
      }
      echo "&lt;/select&gt;";
      echo "&lt;input type='submit' Value='submit' /&gt;";
      echo "&lt;/form&gt;";
  </code></pre>
  
  <p>I am trying to create a dropdown using the above code for my form. But its not working.   There are 3 distinct values in the Branch column but in the dropdown, it shows only one value(the first one) and the next two as blank values. </p>
  
  <p>However when in echo $row_num, its shows 3.<br>
  Thats means its fetching the three rows, but then why its not showing in the dropdown list. </p>
  
  <p>If I run the same query in phpmyadmin it shows the correct answer i.r it returns 3 distinct Branch values.</p>