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 group 1
2 section 2 group 1
3 section 3 group 2
4 section 4 group 1
5 section 5 group 3
I can do a query to get and display unique sec_group values but can't figure out a way to include sec_name into each sec_group
//Query by unique sec_group
$qry_secs="SELECT DISTINCT sec_group FROM tbl_user_sec ORDER BY sec_id ASC";
$result_secs = mysql_query($qry_secs);
//echo values
while($row_secs = mysql_fetch_assoc($result_secs)){
echo '<ul><li><a href="#">'.$row_secs['sec_group'].'</a></li></ul>';
}
Eventually, the HTML should like the code below.
<ul>
<li><a href="#">Group 1</a>
<ul>
<li><a href="#">Section 1</a></li>
<li><a href="#">Section 2</a></li>
<li><a href="#">Section 4</a></li>
</ul>
</li>
<li><a href="#">Group 2</a>
<ul>
<li><a href="#">Section 3</a></li>
</ul>
</li>
<li><a href="#">Group 3</a>
<ul>
<li><a href="#">Section 5</a></li>
</ul>
</li>
</ul>
any ideas?
ORDER BY sec_id ASC. If-you-know-what-I-mean. :)