MySQL Database : How to Fill html select option or combobox with Data Read using PHP Script
Database Connection and Query
<?php
function DB_Execute($sql)
{
$servername = "localhost";
$username = "root";
$password = "root";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error)
{ die("Connection failed: " . $conn->connect_error); }
// Executing Sql Query
$temp = $conn->query($sql);
if ($temp->num_rows > 0)
{ return $temp; }
else
{ return null; }
// Closing connection
$conn->close();
}
$sql = "SELECT SNO FROM CLIENT";
$result = DB_Execute($sql);
Record Number: <select id="sno" onchange="SelectRec()">
<option value="0">Select Record</option>
<?php
$i = 0;
while($row = $result->fetch_assoc())
{
$i = $i +1;
$val = $row['SNO'];
echo "<option value='$i'>$val</option>";
}
?>
</select>
No comments:
Post a Comment