I am displaying a folder tree and want to alternate the colors for each
folder so my database table shows that for example the Apples folder is
located under the Fruits folder.  Therefore I want to know which row is odd
or even so I can assign it different colors.  Incidently, does anyone know
of a more efficient way of displaying a folder tree without doing it
recursively?

id parent_id name
== ========= =======
1      1     Home
2      1     Products
3      2     Fruits
4      2     Vegetables
5      3     Apples


function build_folder_tree(&$output, $parent=1, $indent="")
{
  $qid = mysql_query("SELECT id, name FROM folders WHERE parent_id =
$parent");

  while ($cat =  mysql_fetch_object($qid))
  {
    $output .= $cat->name + $indent; // here is where I want to assign diff.
colors
    if ($cat->id != $parent)
      build_folder_tree($output, $cat->id, $indent."  ");
  }
}

-----Original Message-----
From: John Simpson [mailto:[EMAIL PROTECTED]]
Sent: April 14, 2002 7:18 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: Need row number from database select


If you know you're looking for Bob or Mike or John, you could select the
rows each time in your loop as an associative array.

mysql_fetch_array(result, MYSQL_ASSOC)

will do the trick.

"Sp" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> If this is my database result from a select then I need to know that Bob
is
> the 1st result, Mike is the 2nd result and John is the 3rd result ...
>
> Name     Address
> ======== ===============
> Bob      121 King St.
> Mike     99 Main St.
> John     8433 Albert St.
>
> Does mysql keep track of this?  I know I could just do a $i++ as I loop
> through the results but I'm doing something recursively so the counter
> doesn't work here.
>
>



--
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