$sql = "SELECT DISTINCT Branch FROM student_main"; $result = mysql_query($sql); $row_num = mysql_num_rows($result); $rows = mysql_fetch_array($result); echo "<select name='Branch'>"; for($i=0;$i<=$row_num-1;$i++){ echo "<option value='".$rows[$i]."'>".$rows[$i]."</option>"; } echo "</select>"; echo "<input type='submit' Value='submit' />"; echo "</form>";
I am trying to create a dropdown using the code above for my form. But that does not work. There are 3 different values ββin the Branch column, but the drop-down list shows only one value (the first) and the next two as empty values.
However, when in echo $ row_num it hits 3.
This means that it extracts three lines, but then why it is not shown in the drop-down list.
If I run the same request in phpmyadmin, it shows the correct answer. ir returns three different Branch values.
source share