Populate combo box with data from database

 

<?php
include "connect.php"; 
$query="select * from department";
$rs=mysqli_query($db, $query);//execute SQL command
if($rs==false){//if SQL fail
  echo "SQL error: ".mysqli_error($db);
  exit(0);
} 
if(mysqli_num_rows($rs)==0){//if no record
    echo "Sorry, no record fetched...<br>";
}
else{//ada rekod
  echo "<select name='dept'>\n";
  while ($rekod=mysqli_fetch_array($rs)){
     echo " <option value='".$rekod['DEPTNO']."'>";
     echo $rekod['DEPTNAME']."</option>\n";
    }
    echo "</select> \n";
}
?> 


image

Popular Posts

WorldConferences.net