Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

heirarchy in table.

Status
Not open for further replies.

nitinr

Programmer
Jun 6, 2000
1
IN
i have table catagory with fields:-<br><br>cat_id int(11)PRI auto_increment ¦<br>cat_name&nbsp;&nbsp;varchar(100)¦&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦<br>parent_cat int(11) <br><br>where parent_cat is cat_id of another record.<br>means one record is child of another..<br>how can i display the hierarchy with minimum query..<br>
 
Hi Nitin,
I saw your query posted long back, related to mySQL &quot;how can i display the hierarchy with minimum query..&quot; . I am facing the same problem which you had.I just wanted to know that did you get any solution for the same ?
if yes please let me know I need it very badly.

Thanks and regards
Jaydeep
jaydeep.vaze@solversa.com
 
I'm not sure what &quot;minimum query&quot; means, but if it means &quot;do it with one query&quot;, you can't. To fetch the entire hierarchy in one query would require recursive SQL queries, which MySQL does not support.

Typically, you output the hierarchy using a scripting language.

If you have some value that indicates an entry has no parent (generally a parent_id) of zero, then you use a programming languate to fetch each of these files.

For each file in the list, you fetch its children.

For the first child, you fetch its children

When you run out of children, you return to the next level of the hierarchy and start processing the next sibling of the current record at that (the new) level of the hierarchy.

When you run out of siblings, you're done.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top