Forum Moderators: coopster

Message Too Old, No Replies

Getting all categories under a category

         

maccas

6:05 pm on Nov 7, 2006 (gmt 0)

10+ Year Member



Hi, I have a table say called categories and columns called id,catname,parentid.... now I want to drill down till I get to a certain top level category so I know all the catnames under this particular category. Is there a problem doing FROM categories as alias, categories as alias2,categories as alias3,categories as alias4 .... Is there a better or another way to do this?

ramoneguru

9:43 am on Nov 8, 2006 (gmt 0)

10+ Year Member



So I think I understand this, you have a Category table and the thing that's important is, you want to select all the catnames in that Category table that are below a certain name the user supplies?

One simple method would be to select all the catnames, do a fetch_array of the query results, if the user value is NOT the same as the one in the array, then keep processing each array value. Once you hit the name, return all the results before/after that value.

Is that what you were looking for or did I miss it completely? Aliasing everything is fine if you have like 3 of them.......if you end up with like 34,567 categories then it gets hard to determine what alias3567 might be when debugging.....
--Nick