Searching on categories.
| From: | Roman Sainz | Date: | Thu, 27 Sep 2001 14:26:23 +0000 |
| Subject: | Searching on categories. | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-12788@lists.php.net to get a copy of this message | ||
I have a database like this.
PRODUCTS
id product cat_id
1 keyboard 3
2 mouse 3
3 windows 2
4 PowerPC 4
Then I also have another database like this.
CATEGORIES
id name parent_id
1 PC 0
2 Software 1
3 Hardware 1
4 Mac 0
So categories can have a parent of 0 or another category.
Products have one category.
I can perfectly search for a product in 1 category.
I am having some problems with the recursion involved in searching the subcategories of a category.
I can search like this. SELECT * FROM PRODUCTS WHERE cat_id='2'
The result would be "3 windows 2".
But what if I want to search the whole cat_id 1? (so it will include cat 2 and cat 3)?
Please some one point me.
-Roman.
My other computer is spongy gray matter.