Re: Generating view of tree?

From: Date: Thu, 27 Mar 2003 15:08:47 +0000
Subject: Re: Generating view of tree?
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-26655@lists.php.net to get a copy of this message
If I understand correctly and you have the data all in one table, you can just query all the data that goes into the report, sorted by categories, and output the data in a loop. This code will give you an ordered list indented and numbered by level. It's not perfect, but give you the idea... $qstr="SELECT * FROM table ORDER BY cat1, cat2, cat3"; $rslt=mysql_query($qstr); $cat1="x"; $cat2="x"; $cat3="x"; while ($row = mysql_fetch_array($rslt)) { if ($cat1!=$row['cat1']) { $indent="1-"; $cat1=$row['cat1']; echo "$indent $cat1<BR>"; } if ($cat2!=$row['cat2']) { $indent="&nbsp;&nbsp;2-"; $cat2=$row['cat2']; echo "$indent $cat2<BR>"; } if ($cat3!=$row['cat3']) { $indent="&nbsp;&nbsp;&nbsp;&nbsp;3-"; $cat3=$row['cat3']; echo "$indent $cat3<BR>"; } } Hope that helps. -- Best regards, Randy Wednesday, March 26, 2003, 8:18:50 PM, you wrote: > I have a table with a tree. Thing is, I need to generate a view of it like: > Category > Sub-category > Sub-sub-category > Another sub-category > Another category > Sub-category > Any way to do this, without using a huge number of queries? Using MySQL.

« previous php.db (#26655) next »