liam1412 Posted September 1, 2009 Share Posted September 1, 2009 Hi I am trying to streamline my coding practices and am looking at OOP/MVC If I have 3 tables Categories Forums Posts I could acheive a forum structure quite easily by getting the categories the searching for all forums with that catid and then searching for all posts with that forumid. Obviously this is very clumsy and hard to implement in MVC I need a way to get all this in a multi dimensional array with as few queries as possible. Please go easy on me. I am very new to this. I have been using php for some time, but only at a basic level. The array would need to hold A list of categories > within each category it would need to hold a list of forums that have that catid > then I would need a post/thread count using each forumid. can I do this with joins and if so How do I do it without having sub queries in my view. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/172764-query-to-multi-dimensional-array/ Share on other sites More sharing options...
RussellReal Posted September 2, 2009 Share Posted September 2, 2009 You could query for subcategories.. or.. 'forums' and then in the query run a subquery to gather the catid's name counterpart.. e.g. "SELECT (SELECT name FROM categories WHERE id = catid) As categoryName" so the entire query will look something like this.. "SELECT (SELECT COUNT(*) FROM Posts WHERE forumid = Forums.id) As posts, (SELECT name FROM Categories WHERE id = Forums.catid) As categoryName FROM Forums" THAN you loop through them.. seperate them by categoryName.. and then put them into their places.. Goodluck Quote Link to comment https://forums.phpfreaks.com/topic/172764-query-to-multi-dimensional-array/#findComment-910649 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.