First step is to create the CATEGORY table with category_id and category_name column names and add your data to it like the one below.
CATEGORY Table
![]() |
CATEGORY |
PHP and MySQLi Code
<select>
<?php
$con = mysqli_connect("localhost","root","","sample");
//display values in combobox/dropdown
$result = mysqli_query($con,"SELECT * FROM category ORDER BY category_name");
while($row = mysqli_fetch_assoc($result))
{
echo "<option>$row[category_name]</option>";
}
?>
</select>
Insert the above code between your form tag and save it with the file extension of .php. The first line in your php code is the database connection which contains the hostname (localhost), username (root), password ("") since I have no password in mysql, database name (sample).
Output Display Data in Combobox
Feel free to comment below for any questions. God bless you all! Hope this helps! ^_^
No comments:
Post a Comment