selecing products from differetn categories in search

Discussion in 'PHP' started by dizyn, Feb 16, 2008.

  1. #1
    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.
     
    dizyn, Feb 16, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Well seeing your current code or database structure would surely help.
     
    nico_swd, Feb 16, 2008 IP
  3. dizyn

    dizyn Active Member

    Messages:
    251
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    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):
     
    dizyn, Feb 16, 2008 IP
  4. able

    able Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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.
     
    able, Feb 16, 2008 IP
  5. Ares

    Ares Member

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #5
    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, Feb 17, 2008 IP
  6. able

    able Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    able, Feb 17, 2008 IP