Post here if you need help with SQL.
Carbine
Posts: 58 Joined: Fri May 06, 2011 1:47 pm
Location: UK, Nottinghamshire
Contact:
Post
by Carbine » Fri May 06, 2011 2:11 pm
I'm creating an article system, with catergorys kind of like a forum. I've got sub forums so if you was to click a fourm, the subs will appear in there and it could go on for ever if I made enough sub forums
But I want to count how many articles there is in the forum and in all the sub forums that belong to it.
Here's the link to take a look at what I mean, click the php section and you'll get what I mean:
http://www.comppchelp.com/articles.php
jacek
Site Admin
Posts: 3262 Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:
Post
by jacek » Fri May 06, 2011 2:13 pm
if you can get a list of subforums you can use that in a query
SELECT COUNT(`id`) FROM `articles` WHERE `category` IN (1, 2, 3)
which should get the number of articles in the categories with ids 1, 2 and 3.
What is your database structure like ?
Carbine
Posts: 58 Joined: Fri May 06, 2011 1:47 pm
Location: UK, Nottinghamshire
Contact:
Post
by Carbine » Fri May 06, 2011 2:16 pm
Can't be too sure as it's on my laptop and my new PC doens't have the webhost details nor database.
But I think:
(Catergories)
ID
Type(Not actually need atm)
Parent
Name
Place
(Articles)
ID
Parent
Title
UID
Date
jacek
Site Admin
Posts: 3262 Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:
Post
by jacek » Fri May 06, 2011 2:25 pm
You need a way to get all of the child sections. Hmm.
You may have to not count the posts in sub sections, I don't think most forums do that anyway.
The only way to do it that I can think of would involve a lot of queries.
Carbine
Posts: 58 Joined: Fri May 06, 2011 1:47 pm
Location: UK, Nottinghamshire
Contact:
Post
by Carbine » Fri May 06, 2011 6:30 pm
I'll just count the first sub catergories then, any after that doesn't matter
jacek
Site Admin
Posts: 3262 Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:
Post
by jacek » Fri May 06, 2011 6:35 pm
Carbine wrote: I'll just count the first sub catergories then, any after that doesn't matter
okay
I think you would be able to get the first X pretty easily hmm.