I am stuck!
Please help me out..
I am using this query right now, to produce a list of main categories.
All main categories have the value 0 in ParentID.
SELECT CatID, CatTitle, ParentID
FROM cats
WHERE ParentID = '0'
ORDER BY CatTitle ASC
This query produce a return like:
5,Cars, 0,
6,Cats, 0
and so on..
Now i would like to list main category with some subcategories underneath.
Like this:
Cars
BMW, MB, Rover, Pontiac
All subcategories have value of the main categories CatID as ParentID, but i only want to show the subcategories with a value of 1 in a field called Products.
My table looks like this:
CatID | CatTitle | ParentID | Products
----------------------------------------
5, Cars, 0, 0
6, Cats, 0, 0
7, BMW, 5, 1
8, MB, 5, 1
9, VW, 5, 0
10, Bentley 5, 0
11, Pontiac, 5, 1
How will a query to accomplish this look like?
Please help me out..
I am using this query right now, to produce a list of main categories.
All main categories have the value 0 in ParentID.
SELECT CatID, CatTitle, ParentID
FROM cats
WHERE ParentID = '0'
ORDER BY CatTitle ASC
This query produce a return like:
5,Cars, 0,
6,Cats, 0
and so on..
Now i would like to list main category with some subcategories underneath.
Like this:
Cars
BMW, MB, Rover, Pontiac
All subcategories have value of the main categories CatID as ParentID, but i only want to show the subcategories with a value of 1 in a field called Products.
My table looks like this:
CatID | CatTitle | ParentID | Products
----------------------------------------
5, Cars, 0, 0
6, Cats, 0, 0
7, BMW, 5, 1
8, MB, 5, 1
9, VW, 5, 0
10, Bentley 5, 0
11, Pontiac, 5, 1
How will a query to accomplish this look like?