Hello,
I am trying to add the ability to use sub categories to my database and I need help with a query. My design:
What I would like to do, is pull out all the articles that are for a particular category, and ALL articles in ALL sub categories for that category. I am having trouble with the SQL. I know how to get the articles from one particular category (a la WHERE CatID = 3 ...), but I am having trouble translating that into many categories. I think I need to somehow get the ID's of the children, then pass them into the WHERE clause (WHERE CatID = 3, 4, 5, 6, etc...), but I'm not familiar with how this would be done. Any ideas?Code:CREATE TABLE `Articles` ( `ID` int(11) unsigned NOT NULL auto_increment, `Name` text NOT NULL, `Body` longtext NOT NULL, `Date` datetime NOT NULL default '0000-00-00 00:00:00', `Picture` varchar(100) default NULL, `Description` text NOT NULL PRIMARY KEY (`ID`), ) CREATE TABLE `Categories` ( `ID` int(11) unsigned NOT NULL auto_increment, `ParentID` int(11) unsigned NOT NULL default '0', `Name` varchar(100) NOT NULL default '' PRIMARY KEY (`ID`), UNIQUE KEY `Name` (`Name`) ) CREATE TABLE `CatLookup` ( `ArticleID` int(11) unsigned NOT NULL default '0', `CatID` int(11) unsigned NOT NULL default '0', PRIMARY KEY (`ArticleID`,`CatID`), KEY `CatID` (`CatID`) )
Ben




Bookmarks