Re: Hierarchies
| From: | MindHunter | Date: | Wed, 28 Nov 2001 11:12:38 +0000 |
| Subject: | Re: Hierarchies | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-75877@lists.php.net to get a copy of this message | ||
I've tried to convert this function to ODBC. Anyone that can help?
Tx
MH
Dimitris Kossikidis <kossikidis@vip.gr> wrote in message
news:000801c177eb$adea5500$0300a8c0@mits...
> You can do it only in few lines of code with a recursive function... You
> can display full tree structure with unlimited levels.
>
> Mysql Table :
> cid int,
> parent int,
> Name varchar
>
> Cid parent varchar
> 1 0 A
> 2 1 C
> 3 0 B
> 4 1 D
> 5 2 E
> 6 3 F
> This should output :
>
> - A
> - - C
> - - - E
> - - D
> - B
> - - F
>
>
> function ShowTree($parent=0,$level=0){
> $query=mysql_query("select cid,parent,name from categories where
> parent='$parent'");
> $level++;
> while ($row=mysql_fetch_object($query) ){
> $cnt=$row->cid;
> $element[$cnt]['cid']=$row->cid;
> $element[$cnt]['parent']=$row->parent;
> $element[$cnt]['name']=$row->name;
> echo str_repeat('-', $level)
> ."<B>".$element[$cnt]['name']."</B>
> (level=$level)(counter=$cnt)<br>";
> ShowTree($element[$cnt]['cid'],$level);
> }
> }
>
> ShowTree(0,0);
>
> > -----Original Message-----
> > From: MindHunter [mailto:MindHunter@mailbox.co.za]
> > Sent: Wednesday, November 28, 2001 9:27 AM
> > To: php-general@lists.php.net
> > Subject: [PHP] Hierarchies
> >
> >
> > Hi,
> >
> > I need to display hierarchies (hierarchical structures). I
> > have a MYSQL table with data like this:
> >
> > Node,Parent
> > A,
> > B,A
> > C,A
> > D,B
> > E,B
> > F,D
> > G,A
> >
> > It can go down to 10 levels.
> >
> > I do not want display one level and then click to display the
> > next, I want to see the entire tree at once, say like this:
> >
> > A
> > ---B
> > ------D
> > ---------F
> > ------E
> > ---C
> > ---G
> >
> > Any ideas, scripts on how I can do this? I seems like I have
> > to use a recursive function and /or arrays?
> >
> > Any help will be appreciated!
> >
> > Thanks
> > MH
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail:
> > php-general-help@lists.php.net To contact the list
> > administrators, e-mail: php-list-admin@lists.php.net
> >
>