Jump to content

Recommended Posts

Hello all,

I'm trying to change the way the output look like from Recursion

instead of it looking like this

binary-tree-view.jpg

 

and make it look like this

 

clip-image0244-thumb.jpg

 

 

 

here is my code

 

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

$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

// add this node to the stack
  $right[] = $row['right'];
  }
  echo str_repeat('      ',count($right)).$row['title']."<br>"; 
} 
  
  display_mptt(1);

?>

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.