select option in php using database

I will show you how to add data into select option by fetching data from database. its quite simple. select option is mostly used for registrations & other major activities & forms. select option is useful.

create database named premal. add 1 table named location_country with 2 fields. 1 is for id autoincrement & name.

premal katigar

After that some data into database.

Now get following Code.

<?php
$con=mysql_connect("localhost","root");
mysql_select_db("premal",$con);
?>
<select name="location" id="location">
$query="select name from location_country";
 $result=mysql_query($query);
 if($result)
 {
 ?>
 <option value="NULL">SELECT</option>
 <?php
 while($row=mysql_fetch_array($result))
 {
 ?>
 <option value="<?php $row[0] ?>"><?php echo $row[0] ?></option>
 <?php
 }
 }
 ?> 


</select>