Re: Generating view of tree?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux