$q = mysql_query("SELECT sec_id, sec_name, sec_group FROM tbl_user_sec ORDER BY sec_id");
// prepare data
$groups = Array();
while($w = mysql_fetch_assoc($q)) {
if(!isset($groups[$w['sec_group']])) $groups[$w['sec_group']] = Array();
$groups[$w['sec_group']][] = $w;
}
// display data
echo "<ul>";
foreach($groups as $group_name => $sections) {
echo '<li><a href="#">'.$group_name.'</a><ul>';
foreach($sections as $section) {
echo '<li><a href="#">'.$section['sec_name'].'</a>';
}
echo '</ul></li>';
}
echo "</ul>";
Der er en anden løsning
hvis du er ligeglad med at sortere resultatet efter sec_id