By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,873 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 displaySubordinates($id,$orgbox) {
$sqlquery = "SELECT ID,name,title,dept,level FROM employees WHERE
supervisor = '$id'";

$result = mysql_query($sqlquery);
$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($result,$i,"id");
$name = mysql_result($result,$i,"name");
$title = mysql_result($result,$i,"title");
$dept = mysql_result($result,$i,"dept");
$level = mysql_result($result,$i,"level");
makeOrgBox($name,$title,$dept,$level,$orgbox);
}
displaySubordinates($id,$orgbox);
}
return($orgbox);
}

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

Jun 23 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.