Jump to content

Need help with table structure and generating a query


Naez

Recommended Posts

Okay so I've got a couple tables:

 

 

articles
-----------
id - primary
cat_id - INT index foreign #links up with categories table
author_id - INT index foreign # links up with user table 
title - varchar(255)
body - longtext
url - varchar(255)  # [b]url-safe-tutorial-title-for-seo-links[/b]
-----------

categories
-----------
id - primary
category - varchar(255)
-----------

 

 

The only thing is, I want to seperate things off by level too.

 

So for instance:

 

"Advanced" articles will carry say category id's 3,4,5

"Intermediate" will carry 2

"Novice" will carry cat_id 1

 

with room for expansion of course.

 

 

Now I know a couple ways to do this... add a new table, or add a parent_id field in categories.  But I'm not sure the best way to do this so hralp!

 

And more importantly, how to generate a big-ass query that will do all the following:

 

[b]Novice:[/b]
- Novice Category 1 (2 articles)
[b]Intermediate[/b]
- Intermediate Category 1 (5 articles)
- Intermediate Category 2 (2 articles)
- Intermediate Category 3 (20 articles)
[b]Advanced:[/b]
- Advanced Category 1 (2 articles)

# I know I'll need some semi-intricate joins and groupings, and a COUNT()

 

I'm not exactly the SQL JOINs master so hopefully I can get some hralp.

 

Also on side note should I use longtext or something else for the body?

 

Thanks!

 

EDIT - Double post - locked.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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.