Jump to content

Managing Hierarchical Data in MySQL

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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...