Dropdown list from MySQL
Posted: Sun Aug 24, 2014 7:24 am
Hi all,
I'm running a SQL statement to collect some data and display, which works fine on it's own.
However, I can't work out how to get that data into a dropdown menu. Here is my current code:
I'm obviously missing something or going about it the wrong way when it comes to the <select></select> section but I can't work out what.
Thanks
I'm running a SQL statement to collect some data and display, which works fine on it's own.
However, I can't work out how to get that data into a dropdown menu. Here is my current code:
Code: Select all
<?php
include("php/includes/error_check.php");
include("php/includes/db_config.php");
include("php/includes/check_sql.php");
//SQL statement
$result = mysqli_query($con,"SELECT * FROM tbl_customers");
while($companyname = mysqli_fetch_array($result))
echo "<option value=$companyname[companyname]>$companyname[companyname]</option>";
?>
<select name="dropdown">
<?php echo $result; ?>
</select>
Thanks