In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] says... > 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." "); > } > }
Well, you don't need to know what row number is. Something like: function build_folder_tree(&$output, $parent=1, $indent="") { $color = "red"; // Set var to first option $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 $color == "red" ? $color = "blue": $color = "red"; // Cycle color for each iteration if ($cat->id != $parent) build_folder_tree($output, $cat->id, $indent." "); } } -- David Robley Temporary Kiwi! Quod subigo farinam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php