Articles system

Post here if you need help with SQL.
Post Reply
Carbine
Posts: 58
Joined: Fri May 06, 2011 1:47 pm
Location: UK, Nottinghamshire
Contact:

Articles system

Post by Carbine »

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 :P 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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Articles system

Post by jacek »

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 ?
Image
Carbine
Posts: 58
Joined: Fri May 06, 2011 1:47 pm
Location: UK, Nottinghamshire
Contact:

Re: Articles system

Post by Carbine »

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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Articles system

Post by jacek »

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.
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Articles system

Post by jacek »

http://dev.mysql.com/tech-resources/art ... -data.html

This may be of some use... no way to make it dynamic though :?
Image
Carbine
Posts: 58
Joined: Fri May 06, 2011 1:47 pm
Location: UK, Nottinghamshire
Contact:

Re: Articles system

Post by Carbine »

I'll just count the first sub catergories then, any after that doesn't matter :P
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Articles system

Post by jacek »

Carbine wrote:I'll just count the first sub catergories then, any after that doesn't matter :P
okay ;)

I think you would be able to get the first X pretty easily hmm.
Image
Post Reply