954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Organization CHART

Hello,

What I'm intending to do it's an Organization chart with departments and members.

Basically an organigram with different departments and different members.


This is the MySQL database.
And here is my attempt of doing this horizontally, but i`m kind of stuck.
Could you give me some hints on how to do this ? Thank you!

# --------------------------------------------------------
# Host:                         127.0.0.1
# Database:                     materom
# Server version:               5.1.41
# Server OS:                    Win32
# HeidiSQL version:             5.0.0.3272
# Date/time:                    2010-11-27 12:23:36
# --------------------------------------------------------

# Dumping structure for table materom.organigrama
CREATE TABLE IF NOT EXISTS `organigrama` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `nume` varchar(50) DEFAULT NULL,
  `nivel` int(10) DEFAULT NULL,
  `id_cont` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;

# Dumping data for table materom.organigrama: 7 rows
INSERT INTO `organigrama` (`id`, `nume`, `nivel`, `id_cont`) VALUES (1, 'Szabol Zsoldos', 4, 244), (2, 'Rodica Baciu', 1, 2), (3, 'Matei Baciu', 1, 1), (4, 'Beniamin Suciu', 2, 3), (6, 'Rezso Zsogmond', 3, 247), (5, 'Corinta Contiu', 2, 266), (8, 'Dan Milascon', 4, 248);


/////////// PHP + HTML

<?php
    include('db.php');
    
    $q1 = "SELECT * FROM materom.organigrama AS o INNER JOIN materom.contact AS m ON o.id_cont = m.id WHERE o.nivel = '1' ORDER BY o.nivel";
    $result = mysql_query($q1);

    $q2 = "SELECT * FROM materom.organigrama AS o INNER JOIN materom.contact AS m ON o.id_cont = m.id WHERE o.nivel = '2' ORDER BY o.nivel";
    $result2 = mysql_query($q2); 

    $q3 = "SELECT * FROM materom.organigrama AS o INNER JOIN materom.contact AS m ON o.id_cont = m.id WHERE o.nivel = '3' ORDER BY o.nivel";
    $result3 = mysql_query($q3);  
    
    $q4 = "SELECT * FROM materom.organigrama AS o INNER JOIN materom.contact AS m ON o.id_cont = m.id WHERE o.nivel = '4' ORDER BY o.nivel";
    $result4 = mysql_query($q4);          
    
?>

<html>
<head>    
    
</head>
<body>


<table>
<?php
    while ($row = mysql_fetch_array($result))
    { 
        echo '
              <tr>
                <td>'.$row['nume'].' '.$row['prenume'].''.$row['functie'].'</td>';

              
              while ($nivel2 = mysql_fetch_array($result2))
              { 
                  echo '               
                        <td>'.$nivel2['nume'].' '.$nivel2['prenume'].''.$nivel2['functie'].'</td>';
              }
              
                  while ($nivel3 = mysql_fetch_array($result3))
                  { 
                      echo '               
                            <td rowspan="2">'.$nivel3['nume'].' '.$nivel3['prenume'].''.$nivel3['functie'].'</td>';
                  }          
                      while ($nivel4 = mysql_fetch_array($result4))
                      { 
                          echo '               
                                <td rowspan="1">'.$nivel4['nume'].' '.$nivel4['prenume'].''.$nivel4['functie'].'</td>';
                      
                      }
                  
                  
            
            echo '</tr>';            
    }
?>
</table>

</body>
</html>
szabizs
Junior Poster in Training
57 posts since Jul 2009
Reputation Points: 10
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: