Location: PHPKode > scripts > Binary Tree Representation > binary-tree-representation/binaryTree.php
<?php 
/*
# Author: Vijay Kumar	
# License: Freeware
# Any one Can user this file and edit the Content of this file according to his/her needs
# Purpose: Creates a Binary tree
*/

class Tree
{
		function binarytree($id = 1, $link , $supermember = false, $float = "left", $level =1)
		{
			$level++;
			if($level>3)
			{
				return false;
			}
			$width = 100;
			$res_count = 1;
			if($supermember)
			{	 
				$res_count = 2;  	
			}
			$query = "Select * from binary_tbl where id = $id";
			$res = mysql_query($query, $link) or die(mysql_error());
			$div_witdh =  $width/$res_count;
			while($r = mysql_fetch_object($res))
			{
					echo "<div style='width:$div_witdh%;text-align:center;float:$float'>$r->name<br>";
					$query_member = "Select * from binary_tbl where supermember = $id";
					$res_member = mysql_query($query_member, $link) or die(mysql_error());
					while($rm = mysql_fetch_object($res_member))
					{
								$this->binarytree($rm->id, $link, true, $float, $level);
								$float = ($float=='left')?'right': 'left';
					}		
					echo "</div>";
			}
}
}
Return current item: Binary Tree Representation