Well, I'd take a good look at coding style and logic flow. You've got some things that are exactly right (good practices), but your style is kind of haphazard. I'm not trying to offend, but it looks at the very least like you've got an extra set of curly braces ... and if you're that "careless" (for lack of an accurate word ... again, I'm not trying to criticize, but you really ought to be more careful on that) ... then adding a 3rd level of complexity is likely to cause problems, for sure.
I've cleaned up your style, and added what I think might be what you're asking for in "pseudo code". Does this help?
<?php
//Create Main Category Menu
$subject_set_query= "SELECT * FROM subjects";
$subject_set= mysql_query($subject_set_query, $connect);
if(!$subject_set) {
die("Database Query Failed: " . mysql_error());
}
// I took the above statement to be your bracket style. The opening
// bracket is at the end of line following the conditional; the closing
// bracket is on the line after the conditional block, directly under the
// first letter of the conditonal. This is often called "One True Brace"
// style, or 1TBS. The other popular style is "K&R". In either case,
// the conditional block is indented one "tab" (which is a set amount of
// spaces and should remain the same in all your code).
while ($category = mysql_fetch_array($subject_set)) {
//note the exact indentation of everything inside this loop.
echo "<ul class='cat_set'>";
echo "<li>{$category["menu_name"]} </li> </ul>";
//create sub-category
$sub_category_query= "SELECT * FROM sub_subjects WHERE subject_id = {$category["id"]}";
$sub_category_set=mysql_query($sub_category_query, $connect);
if(!$sub_category_set) {
die("Database Query Failed: ". mysql_error());
}
while ($sub_cat= mysql_fetch_array ($sub_category_set)) {
// another loop, another level of indentation
echo"<ul class='sub_menu'>";
echo"<li>{$sub_cat["menu_name"]}</li></ul>";
// create subject
$somesql="select something from somewhere";
$subject_set=mysql_query($somesql);
while ($something) {
echo $something_else;
echo "a line tag";
} // end "while something"
} // end "while $sub_cat"
} // "end while category"
?>