I'll try and explain this the best I can:
I have this table:
and I am trying to get the following results set:
(a nested tree with each subject under its respective parent).
I am currently doing this with an echo statement and a recursive PHP call.
For multiple reasons (not just that recursion in PHP is nasty) I am trying to obtain the same results from a single mySQL query.
I am using mySQL v.4.0.24, upgrading is not an option.
Can anyone help?
Also if there is anyway the dashes can be recreated that would be awesome.
I've been trying for most of the afternoon evening, but have come up blank.
Thanks for any help you can give
I have this table:
Code:
mysql> select * from subject_areas;
+------------+-------------------+-----------------+
| subject_id | subject_parent_id | subject_area |
+------------+-------------------+-----------------+
| 1 | 0 | mySQL |
| 2 | 0 | installing php |
| 3 | 0 | C++ |
| 4 | 0 | Cisco IP Phones |
| 5 | 0 | Windows |
| 6 | 0 | Linux |
| 7 | 6 | User Management |
| 8 | 5 | Reformatting |
| 9 | 8 | XP |
| 10 | 5 | Network |
| 11 | 9 | Home |
| 12 | 9 | Pro |
+------------+-------------------+-----------------+
and I am trying to get the following results set:
(a nested tree with each subject under its respective parent).
Code:
1-mySQL
2-installing php
3-C++
4-Cisco IP Phones
5-Windows
- 8-Reformatting
- - 9-XP
- - - 11-Home
- - - 12-Pro
- 10-Network
6-Linux
- 7-User Management
For multiple reasons (not just that recursion in PHP is nasty) I am trying to obtain the same results from a single mySQL query.
I am using mySQL v.4.0.24, upgrading is not an option.
Can anyone help?
Also if there is anyway the dashes can be recreated that would be awesome.
I've been trying for most of the afternoon evening, but have come up blank.
Thanks for any help you can give