Page 1 of 1

PHP Recursion - Find Possible Parents

Posted: Fri Dec 01, 2006 5:59 am
by amir
1. I need to use recursion to build a string to use in a dynamic NOT IN query.

2. I want to use a query something like this:

Code: Select all

SELECT DISTINCT f.FileID, f.FileName, f.ThumbnailFileName, f.FileDate, f.FileDescription, f.DateEntered, Citation, Summary, f.FileDate, f.cr, f.enteredBy, f.reviewed, f.Transcript  FROM tblFile f LEFT JOIN tblFileCategory fc ON fc.FileID=f.FileID WHERE fc.CategoryID not in (1,2,3,4);
3. tblCategory Schema:
Category
CategoryID
ParentCategoryID

4. I know the top-level parent I want to use as a 'filter'. But it would be nice to be able to just send this in through the method.

5. For example:
Id ParentId
1
2 1
3 2
4 1
5
6 3

or
1
|_2
|_3
|_6
|_7
|_8
|_9
|_4
5

If my filter id is 1, I want (1, 2, 3, 8) returned to me.

Any advice would be great! Thanks!

Posted: Fri Dec 01, 2006 1:50 pm
by feyd
You may want to look at the hierarchical structures referenced in one or more of our "useful resources" threads found in our various boards. This seems to scream "I need to be redesigned!"