I have done something like this in the past for a document management

Everything was assigned a number, so to find a specific document you
simply referenced "".

It was very simply to create the main index dynamically from this
system. (this is the sort of index you would find on Mysql's website.
http://www.mysql.com/doc/ )

I chose to use periods as the delimiters between parents, but you could
use whatever made sense in your context, and there is no limit to your
depth, as long as your field is defined sufficiently large enough.

In case I'm not being clear, a same table looked like this:

ID      parent  Title                   text
1       .               The first Chapter
1       1               First Text              This is the first page,
first chapter

You would reference that document with ".1.1".. Just replace my
"documents" with your "directories", or whatever unit you're dealing
with. Let me know if this was helpful. :)


- Joel

-----Original Message-----
From: SP [mailto:[EMAIL PROTECTED]] 
Sent: Monday, April 15, 2002 5:32 PM
To: Aj Lavin
Subject: RE: [PHP] Re: Need row number from database select

Hi AJ, very interesting way of displaying a folder tree.  Never thought
it that way.  The problem I see is that you are limited to the depth of
tree because you can't just keep adding a new folder number to the end
the path.  And the total number of folders is limited by the number of
digits you assign per level.  Also why are you using a hex?

-----Original Message-----
From: Aj Lavin [mailto:[EMAIL PROTECTED]]
Sent: April 15, 2002 3:24 PM
To: SP
Subject: Re: [PHP] Re: Need row number from database select

On Sun, Apr 14, 2002 at 09:27:50PM -0400, SP wrote:
> I see what you are trying to do David but that was what I tried first
> doesn't work because the function calls itself depending if it's not a
> parent so the alternating colors become all messed up depending on the
> structure of my folders.  That's why I was hoping to get the number
> of the result returned so I could change the color depending if it was
> or even.
> Any other suggestions?

It is possible to get all of your folders in a single query if you add
a field to your database table that encodes the folder hierarchy


id  path       name
== ========= =======
1      1       Home
2      12      Products
3      123     Fruits
4      124     Vegetables
5      1235    Apples

Here we encode the path using one digit per hierarchy level. The path
encoding for any folder equals the path encoding of its parent plus
the encoding of its id.

If the digits are hex, then this works as long as there are no more
than 16 elements in any level of the hierarchy.  If you need more, you
can use multiple digits per level. I use 8 hex digits to encode 4 byte
int's at each level. You would have shorter path names using base 60.

In PostgreSQL, to get the Products directory and all its
subdirectories, in order, use:

$root = "12";

$result = pg_exex( $db, "SELECT * FROM folders WHERE path LIKE
ORDER BY path ASC");

Sorry, I don't know MySQL, but all you need to know here is that the
'%' char above is a wild card character, like '*' on the command line.

Now you can iterate over the records stored in result. They are in the
proper order. The level of any record is the length of the path string
divided by the number of digits per level.

Hope this helps.

- Aj

PS: My posts don't show up on the PHP list for some reason, so I am
also sending you this directly.

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to