Gotharious Posted November 12, 2011 Share Posted November 12, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/250993-displaying-php-results-in-javascript-code-from-google/ Share on other sites More sharing options...
trq Posted November 12, 2011 Share Posted November 12, 2011 See json_encode. Quote Link to comment https://forums.phpfreaks.com/topic/250993-displaying-php-results-in-javascript-code-from-google/#findComment-1287582 Share on other sites More sharing options...
Gotharious Posted November 12, 2011 Author Share Posted November 12, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/250993-displaying-php-results-in-javascript-code-from-google/#findComment-1287584 Share on other sites More sharing options...
trq Posted November 12, 2011 Share Posted November 12, 2011 I'm not going to write the code for you. Where are you stuck? Quote Link to comment https://forums.phpfreaks.com/topic/250993-displaying-php-results-in-javascript-code-from-google/#findComment-1287686 Share on other sites More sharing options...
Gotharious Posted November 13, 2011 Author Share Posted November 13, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/250993-displaying-php-results-in-javascript-code-from-google/#findComment-1287735 Share on other sites More sharing options...
trq Posted November 13, 2011 Share Posted November 13, 2011 I'm not sure what else I can suggest. Maybe you need to find a developer? Quote Link to comment https://forums.phpfreaks.com/topic/250993-displaying-php-results-in-javascript-code-from-google/#findComment-1287757 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.