It's a bit unclear what you want but I'll try. Im not really *that* good with SQL yet, though, but how about this?
PHP Code:
// The SQL query // SELECT name, items.id as itemID, itemname FROM cat,items WHERE cat.id=items.idcat GROUP BY name
// run query etc.
$prev = ''; $newGroup = false; while($row = mysql_fetch_assoc($result)) { // or use fetch_row if you prefer that $newGroup = ($prev == $row['name']) ? false : true; $prev = $row['name']; if ($newGroup) { $group = ucfirst($row['name']); // first capital letter echo "<optgroup label=\"$group\">"; } echo "<select value=\"" . $row['itemID'] . "\">" . $row['itemname'] . "</select>"; if ($newGroup) { echo "</optgroup>"; } }
Last edited by lizciz; 02-17-2009 at 03:22 PM..
|