Jump to content

Managing Hierarchical Data in MySQL


regicidedelferoz

Recommended Posts

good day everyone! i have a question about Managing Hierarchical Data in MySQL of mike hillyer (http://mikehillyer.c...-data-in-mysql/) i already did what he taught in that website and this is the result of the query but i want to do is to show all categories in one column order by categories.. for example:category 1- category 1.1-- category 1.1.1-- category 1.1.2- category 1.2-- category 1.2.1...category 3category 4and so on thanks in advancemore power

Edited by Regicide Del Feroz
Link to comment
Share on other sites

anyways this is the query i used

 SELECT t1.title AS lev1, t2.title as lev2, t3.title as lev3, t4.title as lev4FROM tbl_news2_cat AS t1LEFT JOIN tbl_news2_cat AS t2 ON t2.parent_category = t1.idLEFT JOIN tbl_news2_cat AS t3 ON t3.parent_category = t2.idLEFT JOIN tbl_news2_cat AS t4 ON t4.parent_category = t3.idWHERE t1.parent_category=0

Link to comment
Share on other sites

Assuming you want to order the categories in a heirarchical order instead of alphabetically, you can't do that with a single query with the adjacency list model. The common way to do that would be to use another language like PHP to implement a recursive function that displays categories and their children.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...