I want to have a dynamic menu that feeds from a table using php and mysql.
My table looks like this:
sec_id sec_name sec_group
1 section 1 g
$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 "";
foreach($groups as $group_name => $sections) {
echo '- '.$group_name.'
';
foreach($sections as $section) {
echo '- '.$section['sec_name'].'';
}
echo '
';
}
echo "
";
There is another solution if you don't care about sorting result by sec_id