Can somebody help me with the following problem:
I want to select all the entries (in this case, categories) from one table. I can do this fine with this code:
$select = @("SELECT * FROM category_kb");
while($fetch = @mysql_fetch_array($select)) {
Now, in category_kb table there are 3 fields: cid, name, and parent. The problem I have has to do with the parents. Let's say that there are 5 categories without parents, and the rest each have a parent.
Cat 1
-- SubCat 1
----SubCat 2
----SubCat 2
------Sub Cat 3
--------And even deeper (infinetely)
--Subcat 2
----Subcat 1
Cat2
etc..
So, I want to be able to show something like that given just one query. I want it to calculate the depth and the put ---- depending on how deep it is just from this one query. Can someone show me how to do this?
If this cannot be done, please tell me how to do it with the least amount of queries possible.
Thanks.