Hi AJ, very interesting way of displaying a folder tree. Never thought of it that way. The problem I see is that you are limited to the depth of the tree because you can't just keep adding a new folder number to the end of 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 Cc: [EMAIL PROTECTED] 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 but it > 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 for each > of the result returned so I could change the color depending if it was odd > 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 positions. Example: 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 '{$root}%' 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