Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    165
    Thanks
    38
    Thanked 2 Times in 2 Posts

    tree style org chart with dynamic input

    Hi,

    All I am here today with new project start & this time my plan is to create a org chart dynamically using Mysql.

    Some how I have started following below link as a part of learning but, I find some huddles when i am doing in PHP to show user.

    I am using 2 things specially one is the above said tutor + org chart jquery.

    Code:
    http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
    https://github.com/wesnolte/jOrgChart
    But still I am not able to make out results as below. any help is appreciated.

    Code:
                         --[EMPLOYEE1]
             -[MANAGER1]-|-[EMPLOYEE2]
    [OWNER]-|                                --[EMPLOYEE3]
             -[MANAGER1]-[ASSISTANT MANAGER]-|-[EMPLOYEE4]
                                             --[EMPLOYEE5]

  • #2
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    165
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Hi frieds,

    I have started with below code.

    Code:
    <?php session_start(); 
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test Page</title>
    <link href="/monitor/style.css" rel="stylesheet" type="text/css" />
    <link rel="icon" href="/monitor/images/icon.ico"/>
    <script language="javascript" type="text/javascript" src="/js/csshorizontalmenu.js"></script>
    <script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="/js/jquery.jOrgChart.js"></script>
    <script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
    <script>
    jQuery(document).ready(function() {
        $("#org").jOrgChart({
        dragAndDrop  : false
    })});
    </script>
    </head>
    <body>
    <div id="header">
    <div class="center">
    <div id="logo"><a href="#">Test Page</a></div>
    <div style="width:760px; height:5px; float: right; margin:70px -150px 0 0; padding:0px;">
    <div class="horizontalcssmenu">
    <ul id="cssmenu1">
    <li><a href="#" Style="">UserName:<?= $_SESSION['myusername'] ?></a></li>
    		
    					<li><a href="main.php">Home</a></li>									
    </ul>
    </div>
    <br style="clear: left;" />
    </div>
     </div>
     </div>
     <?
     include_once "C:/xampp/htdocs/monitor/include/db.php";
     $sql=mysql_query("SELECT t1.Employee_name AS lev1, t2.Employee_name as lev2, t3.Employee_name as lev3, t4.Employee_name as lev4
    FROM org_chart AS t1
    LEFT JOIN org_chart AS t2 ON t2.employee_manager = t1.sno
    LEFT JOIN org_chart AS t3 ON t3.employee_manager = t2.sno
    LEFT JOIN org_chart AS t4 ON t4.employee_manager = t3.sno
    WHERE t1.Employee_name = 'CEO';")or die(mysql_error());
    ?>
     
     <!-- Start of Data -->
     <div class="sample webkit-scrollbar">
    <?while($info=mysql_fetch_array($sql)){?>
      <table border= "0" Id="table1" class="mytable filterable" style="margin:100px 0 0 0; left:-1100px;">
    <tr>
    							<ul id="org">
    							<li> <?=$info['lev1'];?>
    							<ul>
    								<li><?=$info['lev2'];?>
    									<ul>
    										<li>
    											<?=$info['lev3'];?>	
    										</li>		
    									</ul>
    								</li>
    							</ul>
    							</li>
    							</ul>
    </tr>
    </table>
    </div>					
    <?}?>		
    <!-----end of the data --->
    </body>
    </html>
    and table is

    Code:
    sno	Employee_name	employee_manager
    1	0	CEO
    2	1	Director 1
    3	1	Director 2
    4	1	Director 3
    5	3	Manager 1
    5	4	Manager 1
    6	2	Manager 2
    7	2	Manager 3
    8	2	Manager 4
    9	5	Worker 1
    10	5	Worker 2
    11	6	Worker 3
    11	7	Worker 3
    11	8	Worker 3
    12	6	Worker 4
    12	7	Worker 4
    12	8	Worker 4
    13	6	Worker 5
    13	7	Worker 5
    13	8	Worker 5
    But i am getting branches not whole try can any one spark me with idea how I can do it.

    Regards,
    Nani
    Last edited by nani_nisha06; 03-22-2013 at 02:44 PM.

  • #3
    Regular Coder
    Join Date
    Aug 2012
    Posts
    142
    Thanks
    39
    Thanked 3 Times in 3 Posts
    There are lots of tree structures out there that should work for you. Here's one that I use all the time. The reference to the class is a style sheet that I use to create drop down lists so you can hide the child lists if you would like.
    PHP Code:

          <?php
                $parentid 
    0// assuming that 0 is the main category.
                
    get_sub_cats($parentid);
                function 
    get_sub_cats($parentid) {
                
                
    $sql "SELECT * FROM yourTable WHERE parentID = ".$parentid.""
                
    $run mysql_query($sql);
                
                echo 
    '<ul class="aqtree3clickable">';
                    while (
    $rec mysql_fetch_assoc($run)) { 
                    echo 
    '<li />',
                    
    $rec['id'], ' - ',  $rec['childName']; 
                    
    get_sub_cats($rec['id']);
                    }
                echo 
    '</ul>';
                }
            
    ?>
    The childName would be the name of your employee, the parent ID would be the ID of the manager. So if Manager1 was to be the manager of employee 3 and employee 9 then the Manager 1, employee 3 and employee 9 table would look like this:
    1, Manager 1 name, 0
    3, employee 3 name, 1
    9, employee 9 name, 1

    if employee 3 was supervising employee 5 then the employee 5 row would look like this:

    5, employee 5 name, 3

    The resulting table would look like this:
    • Manager 1 Name
      • employee 3 name
        • employee 5 name


      • employee 9 name


    Any row with a parentID of 0 would be first level, any row with another value would be a child of that parent. This is a recursive list so if there were tens of thousands of names in the list it would slow down. ParentID would correspond to your employee_manager column.
    Last edited by rgEffects; 03-22-2013 at 05:37 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •