Group organizational chart

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Group organizational chart

Post by xionhack »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hello, I have a project that I've been working for a while but havent been able to do it. I have to make a table that goes first in the header the group leader, then in the second row it's going to appear the different team leaders that are bellow that group leader, and then bellow every team leader, the members that are bellow him.

I have tried different ways to make the sql tables but I dont know if im doing it right, I'll paste an html code to show kinda what I am looking for. I will really appreciate if someone can help.

Code: Select all

 
<table border="1">
  <tr>
    <th colspan="4" scope="col">Group Leader 1</th>
  </tr>
  <tr>
    <td>Team Leader 1</td>
    <td>Team Leader 2</td>
    <td>Team Leader 3</td>
    <td>Team Leader 4</td>
  </tr>
  <tr>
    <td>Member 1</td>
    <td>Member 5</td>
    <td>Member 8</td>
    <td>Member 12</td>
  </tr>
  <tr>
    <td>Member 2</td>
    <td>Member 6</td>
    <td>Member 9</td>
    <td>Member 13</td>
  </tr>
  <tr>
    <td>Member 3</td>
    <td>Member 7</td>
    <td>Member 10</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Member 4</td>
    <td>&nbsp;</td>
    <td>Member 11</td>
    <td>&nbsp;</td>
  </tr>
</table>
 
<table border="1">
  <tr>
    <th colspan="3" scope="col">Group Leader 2</th>
  </tr>
  <tr>
    <td>Team Leader 5</td>
    <td>Team Leader 6</td>
    <td>Team Leader 7</td>
  </tr>
  <tr>
    <td>Member 14</td>
    <td>Member 18</td>
    <td>Member 21</td>
  </tr>
  <tr>
    <td>Member 15</td>
    <td>Member 19</td>
    <td>Member 22</td>
  </tr>
  <tr>
    <td>Member 16</td>
    <td>Member 20</td>
    <td>Member 23</td>
  </tr>
  <tr>
    <td>Member 17</td>
    <td>&nbsp;</td>
    <td>Member 24</td>
  </tr>
</table>
 
 
 

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Re: Group organizational chart

Post by socket1 »

To get started, how much experience do you have in PHP / MySQL ?
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Re: Group organizational chart

Post by xionhack »

I have some experience, have been working with it for the past 5 months only, but have some knowledge of them.
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Re: Group organizational chart

Post by socket1 »

Would there be multiple tables for each group (like group_1, group_2) or just one table containing all the groups, teams and members?
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Re: Group organizational chart

Post by xionhack »

The database and the way to call it from the php! I've tried many different ways and at the end is not good. I designed 3 tables

group table, with group_id (pk) and group_leader (here goes the id of the member that is a group leader)

team table, with team_id (pk) , team_leader (here goes the id of the member that is a team leader),
group_id (here goes the id of the group that team belongs to)

member table, here is all the info of the members and one column called team_id that is the id of the team that member belongs to.

I am very new at php, I'm going to post the code I have so far, please criticize it as much as you can! I want to become a good programmer! thanks!

Code: Select all

<div>
   <?php //Get groups and put them in a different table
      $group_set = get_groups(); // function calls all the groups
      while($groups = mysql_fetch_array($group_set)){
         $output .= "<table border=\"1\">\n";
         $output .=   "<th>\n";
            $output .=   "<td>";
               $group_leader = get_personal_data($groups['member_id']); //function gets the personal info of the member through the id      
            $output .=   $group_leader['first_name'] . " " . $group_leader['last_name'] ; //Display the first name and last name
            $output .=  "</td>\n";
         $output .=   "</th>\n";
         
               $team_leader_set = get_t_leader($groups['member_id']); //function calls all the teams
             $output.= "<tr>\n";
                  while($team_leader = mysql_fetch_array($team_leader_set)){
                  $output .= "<td>";
                        $team_leader = get_personal_data($team_leader['member_id']); //function gets the personal info of the member through 
                  $output .= $team_leader['first_name'] . " " . $team_leader['last_name'] . "</td>";
         $output .=     "</tr>\n";
               }
         
                      
         $output .=  "</table>\n";
         
      }
      echo $output;
      ?>
         
</div>
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Re: Group organizational chart

Post by socket1 »

I'm writing something right now (not promising anything) with the 3 different tables, I have them all setup. I'll post the code here when I'm finished. It pretty much follows your code and the look of your original table.
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Re: Group organizational chart

Post by xionhack »

Thanks!
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Re: Group organizational chart

Post by socket1 »

How soon do you need this done? I got about 100 lines of code done and got stuck on echoing the members of each team and then realized it could probably be done with MySQL joins.... I could probably finish that by the end of the week.
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Re: Group organizational chart

Post by xionhack »

Lol! I need it as soon as possible and right where you are I think is where I am stuck too!! I am going to continue working on it, if I have it before you then I'll post the code! Thanks!
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Re: Group organizational chart

Post by xionhack »

I can display de group leaders and the team leaders bellow the respective group leader. But I cannot display de members bellow their team leaders
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Re: Group organizational chart

Post by socket1 »

Yeah I have got to the same point.... my head is about to explode trying to think logically about how to do it. I do have a second idea on how to do this... which I could possibly give an attempt at this weekend if you can wait that long. Thanks
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Re: Group organizational chart

Post by xionhack »

Yes, I can wait I guess... Im stuck!
Post Reply