How to create combobox using php code?
Snippet Code
The following php code can be used to create combobox. This simple example is used to create combobox by fetching data from mysql table.
<?php
$link = mysql_connect("localhost", "root", "");
$conn=mysql_select_db('testdb',$link);
$query = "SELECT * FROM usertable";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result)!=0)
{
echo '<select name="slct">
<option value=" " selected="selected">Choose one</option>';
while($row = mysql_fetch_array( $result ))
{
echo '<option value="'.$row['name'].'">'.$row['name'].'</option>';
}
echo '</select>';
}
?>
Tags