Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/172764-query-to-multi-dimensional-array/
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.