RJP1 Posted March 11, 2011 Share Posted March 11, 2011 Hi guys, I'm building a category table in Joomla and have this so far: id | name | parentid ------------------------- 1 | cat1 | 2 2 | cat2 | 0 3 | cat3 | 0 As you can see, categories 2 and 3 are parents (parentid = 0) but cat 1 is categorised under cat 1. What is the best way to select subcategories straight after it's parent? E.g. cat2, cat1, cat3 to then go on to put them in a table. Would it be best to prevent runaway categorisation and just allow categories and subcategories? Cheers for the guidance. RJP1 Quote Link to comment https://forums.phpfreaks.com/topic/230380-best-way-to-select-categories-then-subcategories-and-order-as-such/ Share on other sites More sharing options...
fenway Posted March 13, 2011 Share Posted March 13, 2011 What's runaway categorization? Quote Link to comment https://forums.phpfreaks.com/topic/230380-best-way-to-select-categories-then-subcategories-and-order-as-such/#findComment-1186832 Share on other sites More sharing options...
RJP1 Posted March 13, 2011 Author Share Posted March 13, 2011 What I meant by runaway categorisation was: Parent - child 1 - child 1's child - etc - child 2 But I have figured out how to prevent this in my application, but I have yet to figure out how to get a list of parents then each parents child categories like so: - parent - child - child - parent - parent - parent - child etc I'll have a look at it now and see if I can figure it out, I managed the harder query in my other post you thought this was like. They are similar and I apologise for the seemingly double post. Cheers, RJP1 Quote Link to comment https://forums.phpfreaks.com/topic/230380-best-way-to-select-categories-then-subcategories-and-order-as-such/#findComment-1186932 Share on other sites More sharing options...
fenway Posted March 13, 2011 Share Posted March 13, 2011 Well, if you can ensure that there's only one level of nesting, then a simple join should be able to generate that list. Quote Link to comment https://forums.phpfreaks.com/topic/230380-best-way-to-select-categories-then-subcategories-and-order-as-such/#findComment-1187009 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.