Select with Optgroup – populated from MySQL Database
I am trying to get a select box with optgroup to populate from a MySQL database. The problem is I can’t see how to get the WHERE clause to work.
Here is an example of the code I am using. Currently it displays the optgroups correctly (these are manufacturers) but it lists all cars.
How can I add a WHERE clause to get only cars that match the manufacturer to appear under the optgroup.
Code:
<select>
<?php
$manufacturer = mysql_query("SELECT * FROM cars");
while($manufacturer_row = mysql_fetch_array($manufacturer )){
echo "<optgroup label='$manufacturer_row[manufacturer]'>";
$car = mysql_query("SELECT * FROM cars");
while($car_row = mysql_fetch_array($car)){
echo "<option>$car_row[car]</option>";
}
}
?>
</optgroup>
</select>
View full post on Tycoon Talk
Database, from, mySQL, Optgroup, populated, Select