GD org chart -- image display problem... One function works, the other does not...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Crystal

    GD org chart -- image display problem... One function works, the other does not...

    I have created a small program that prints out an organization chart in
    PHP using the GD lib's imagecreate, imageline and imagestring
    functions. Basically, a user selects an employee from a drop-down list
    to generate an on-the-fly graphical organization tree. A function is
    called to set the selected employee's data into an imagestring and draw
    imagelines around it. Next a recursive function is called to query for
    and display all direct reports in a hierarchal tree style format.

    The code was working just fine until I separated the logic into two
    separate functions. The problem is that now that I have set up the
    code to be a recursive function, the image no longer will display.
    When the recursive part of the code (below) is commented out, the first
    function works fine. Both functions call a third function
    "makeOrgBox ()" to get the x,y positions of all imagestrings and
    imagelines for the passed employee so the third function takes the
    exact same args.

    Anybody know of any issues when looping over results to build
    imagestrings and imagelines? What about problems using the same image
    handler in multiple functions? I am completely stumped since both
    functions work independently, but the recursive function will not
    produce the imagestrings or the imagelines and all I get is the dreaded
    x in the box to indicate a missing image. Thanks in advance for your
    help.

    Problem Code Snippet...
    ------------------------------------
    function displaySubordin ates($id,$orgbo x) {
    $sqlquery = "SELECT ID,name,title,d ept,level FROM employees WHERE
    supervisor = '$id'";

    $result = mysql_query($sq lquery);
    $total_rec = mysql_num_rows( $result);
    $i = 0;
    if ($total_rec > 0)
    {
    // process the results
    for($i=0; $i < $total_rec; $i++){
    $id = mysql_result($r esult,$i,"id");
    $name = mysql_result($r esult,$i,"name" );
    $title = mysql_result($r esult,$i,"title ");
    $dept = mysql_result($r esult,$i,"dept" );
    $level = mysql_result($r esult,$i,"level ");
    makeOrgBox($nam e,$title,$dept, $level,$orgbox) ;
    }
    displaySubordin ates($id,$orgbo x);
    }
    return($orgbox) ;
    }

    function makeOrgBox($nam e,$title,$dept, $level,$orgbox) {
    // $orgbox is the image handle
    ....

Working...