Naez Posted October 14, 2008 Share Posted October 14, 2008 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 https://forums.phpfreaks.com/topic/128456-need-help-with-table-structure-and-generating-a-query/ Share on other sites More sharing options...
Recommended Posts