PHP Recursion - Find Possible Parents

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

PHP Recursion - Find Possible Parents

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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!"
Post Reply