Jump to content

Please help me display a tree


d4rkpr1nc3

Recommended Posts

Hi,

I need help with displaying a tree from a mysql tabel. I use the recursive function bellow to extract the values from the table, and then i try do display a grafical tree using lines and images. The function works pretty good but i have problems with creating the graphical tree. the mysql table contain the field "id" and "sponsor_id" which i am using for extraction. Basicaly, i need help with styling the nested lists so that they form a "tree".

This is the function.

 

function diagram($id)
                    {
                        $return="<ul id='tree' style='margin-left:".$margin."px; margin-top:-10px'>";
                        $sql="SELECT * FROM users WHERE sponsor_id='$id'";
                        $result=mysql_query($sql);
                        if(mysql_num_rows($result))
                            while($row=mysql_fetch_array($result))   
                            {
                               
                                $return.="<li style=$style>";
                                $return.="<img src='images/vertical.png' style='width:2px; height:10px; margin-bottom:-8px; margin-top:0px'><br />";
                                $return.="<img src='images/c_black.gif' alt='ID:$row[xangoid]; Name:$row[prenume] $row[nume]' title='ID:$row[xangoid]; Name:$row[prenume] $row[nume]'>";
                                if(mysql_num_rows(mysql_query("SELECT * FROM users WHERE sponsor_id='$row[id]'")))
                                    $return.="<br /><img src='images/vertical.png' style='width:2px; height:10px; margin-top:-8px'>";
                                $return.=diagram($row['id']);
                                $return.="</li>";
                        }
                        $return.="</ul>";
                        return $return;
                    }

Link to comment
https://forums.phpfreaks.com/topic/240613-please-help-me-display-a-tree/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.