Friday 12 February 2016

Dropdown list with data from MySQL table

Code:

<!DOCTYPE html>
<html>
<body>
<center><h1>Dropdown list with data from MySQL table</h1>
    <select name="district">
      <option value="" hidden>District</option>
      <?php
        $conn=mysqli_connect('localhost','root','','bloodlist');
        $query="SELECT * FROM districts ORDER BY dis_name ASC";
        $result=mysqli_query($conn,$query);
        while ($distr=mysqli_fetch_assoc($result))
        {
          echo "<option value=".$distr['dis_id'].">".$distr['dis_name']."</option>";
        }
      ?>
    </select>
</center>
</body>
</html>



Output:

No comments:

Post a Comment