Categorized Query Output

A

Anonymous

Guest
Hello, I'm trying to make like a tree structure output. Something like this:

Engineering Department
---> First Year
--------> Mechanical Engineering
--------> Electrical Engineering
--------> Computer Engineering
--------> Civil Engineering
---> Second Year
--------> Mechanical Engineering
--------> Electrical Engineering
--------> Computer Engineering
--------> Civil Engineering
---> Third Year
--------> Mechanical Engineering
--------> Electrical Engineering
--------> Computer Engineering
--------> Civil Engineering

Technical Department
---> First Year
--------> Mechanical Technology
--------> Electromechanical Technology
--------> Telecommunicatiuon Technology
--------> Electronics Technology
---> Second Year
--------> Mechanical Technology
--------> Electromechanical Technology
--------> Telecommunicatiuon Technology
--------> Electronics Technology
---> Third Year
--------> Mechanical Technology
--------> Electromechanical Technology
--------> Telecommunicatiuon Technology
--------> Electronics Technology

These are my MYSQL tables:
department - top level
year_level - second level
courses - lowest level

Thanks in advance!
 
Well, then, in each of the sub-tables you have to have a column that describes which row in its parent table is its parent. Then when you can select all of the top-level rows, and then for each of those rows select all of the rows from the second-level table which have a parent_id that equals that row's ID, and then for the third level you can do the same. This will require one query for each of the second-level rows, so, in your example, it'll take 7 queries total. Do this in a loop and it won't be a problem.
 
Back
Top