Jump to content

Displaying PHP results in Javascript code from Google


Gotharious

Recommended Posts

Hello all,

I want to make this recursive function of php

 


<?
$user = $_GET['id'];
echo '<hr>'; 
function display_mptt($user) {
global $db;
// retrieve the left and right value of the $root node
$sql2 = "SELECT * from mptt where id= ".$user."";

$result2 = mysql_query($sql2 ,$db);
if(!$row2 = mysql_fetch_array($result2)) echo mysql_error();
echo '<h1>Your Tree</h1>';

// start with an empty $right stack
$right = array();

// now, retrieve all descendants of the $root node
  $sql = "SELECT * from mptt WHERE `left` BETWEEN ".$row2['left']." AND ".$row2['right']." ORDER BY 'left' ASC";
$result = mysql_query($sql ,$db);

// display each row
  while ($row = mysql_fetch_array($result)) {
  // only check stack if there is one
  if (count($right)>0) {
  // check if we should remove a node from the stack
  while ($right[count($right)-1]<$row['right']) {
  array_pop($right);
  }
  }
// display indented node title
  echo str_repeat('            ',count($right)).$row['title']."<br>";
// add this node to the stack
  $right[] = $row['right'];
  }
} 
  
  display_mptt(1);
?>

 

Appear in a structure like the one from Google Chart located here

 

http://code.google.com/apis/chart/interactive/docs/gallery/orgchart.html

 

and here is their code

 

<html>
  <head>
    <script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>
      google.load('visualization', '1', {packages:['orgchart']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Name');
        data.addColumn('string', 'Manager');
        data.addColumn('string', 'ToolTip');
        data.addRows([
          [{v:'Mike', f:'Mike<div style="color:red; font-style:italic">President</div>'}, '', 'The President'],
          [{v:'Jim', f:'Jim<div style="color:red; font-style:italic">Vice President</div>'}, 'Mike', 'VP'],
          ['Alice', 'Mike', ''],
          ['Bob', 'Jim', 'Bob Sponge'],
          ['Carol', 'Bob', '']
        ]);
        var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
        chart.draw(data, {allowHtml:true});
      }
    </script>
  </head>

  <body>
    <div id='chart_div'></div>
  </body>
</html>

Link to comment
Share on other sites

Ok, thanks thorpe, I checked that but didn't get a clue of what I should do.

 

What I'm trying to do here is to make the tree that looks like this

 

1

  2

  3

    4

    5

    6

      7

        8

 

to look like this

 

http://sameh.files.wordpress.com/2006/05/Organization%20Structure2.jpg

 

Link to comment
Share on other sites

Well, all I can do is make it appear in a table that's all

 

but I just can't make it look well structured

 

I read the page you refered me to, but I didn't know what should I do

 

I figured I would just merge that code from google with the code of the recursion, but just don't know how

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.