Hi all I have n level sub categories and i want to implement search in them. the problem is that if you if you select a parent category you have to go in all the sub and sub sub categories and search in them. I wanted to know how can i search in sub categories of of a categories, remember the system has n level categories.
here is db structure: CREATE TABLE `category` ( `PK_ID` int(11) NOT NULL auto_increment, `parentid` int(11) NOT NULL default '0', `name` varchar(255) default NULL, `last_updated` datetime default NULL, `sort` int(5) default NULL, PRIMARY KEY (`PK_ID`) ); Code (markup):
The simple answer is you can't search the structure easily with your current setup. Take a look at this sitepoint.com/article/hierarchical-data-database/2 - it discusses your problem and a solution.
well actually that's really easy , I dont know how you are doing this but if you just enter the category id in product table, you can select the product so easily : Select * From product where cat_id=13 which cat_id can be a sub category or a parent category , all you have todo is create a field in product table !
Ares I beleive the point is the query should address category 13, and any children, and children could be at any depth. Using a query that checks a single ID as yours, should category 13 have 20 children, you would need to issue an additional 20 queries.