Use an "ORDER BY" criteria in your query and check when the "manufacturer" column data changes, then insert your optgroup.
__________________
Chris. ->> Please login or register to view this content. Registration is FREE <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
So, you want to list all cars under their respective manufacturer?
PHP Code:
// run your query, something like // "select manufacturer, car from cars order by manufacturer"
// manufacturer of the previous car $previous = "";
// just a little help variable $first_car = true;
while($row = mysql_fetch_array($manufacturer)) {
// if this car is of another manufacturer than the last one, // add a new optgroup if ($row['manufacturer'] != $previous) { if (!$first_car) { echo '</optgroup>'; } else { first_car = false; } echo '<optgroup label="' . $row['manufacturer'] . '">'; $previous = $row['manufacturer']; }
// print the current car echo '<option>' . $row['car'] . '</option>';
} // close the last optgroup tag echo '</optgroup>';
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.