Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.