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

, , , , ,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Adobe Flash playerPlugin by wpburn.com wordpress themes


RSS Site FeedRSS Site Feed

© 1992-2011 DC2NET™, Inc. All Rights Reserved