Hi, All
Presently I am working on a MLM (Multi Level Marketing) Software using PHP & MySQL. But I am not being able to display the Down line Tree of any particular member. I am using Pre order Tree. But my product should support Spill Over Binary Tree. Please Help me to develop the tree view. Thanks in advance.

Give the detailed data model. The specs, and the flow that you want the program to follow.

. Please Help me to develop the tree view. Thanks in advance.

Without showing effort your thread will die young. explain more with some code, what you have done and where is the problem!

Here is my table -
Mem_id, Sponsor_id, Spill_id, Spill_Hand(L/R), Date_of_joining, lft, rgt

Now I would like to show the down line tree of any member when s/he logs in. I have tried with JQuery (http://frank-mich.com/jQuery), but its not working. Basically it is not showing the box. But I would like to have a tree like that in my page. Please help.

Here is the page code -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-ie" />
<meta name="robots" content="all" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="copyright" content="" />
<meta name="author" content="" />
<meta name="Rating" content="General" />
<link rel="shortcut icon" href="" type="image/x-icon" />
<link rel="stylesheet" type="text/css" media="all" href="css/glob_nav.css" />
<link rel="stylesheet" type="text/css" media="all" href="css/template.css" />
<script type="text/javascript" src="wz_jsgraphics.js"></script>
<script type="text/javascript" src="jquery-1.4.min.js"></script>
<script type="text/javascript" src="jquery.btree.js"></script>

<script type="text/javascript">
var myTree;
$(function(){
	myTree = $("#treeDiv").btree()[0];
});

function redraw(){
	myTree.clear();
	myTree = $("#treeDiv").btree({
		branchColor: $("#color").val(),
		branchStroke: $("#stroke").val(),
		hSpace: $("#hSpace").val(),
		vSpace: $("#vSpace").val(),
		borderWidth: $("#border").val(),
		horizontal: $("#horizontal").attr('checked'),
		flip: $("#flip").attr('checked')
	})[0];
}

function mich(){
	$("#box1").css("left", "");
	alert($("#box1").css("left") + " - " + $("#box1").css("right"));
}
</script>
<title>TITLE</title>
<style type="text/css">
body{
	font-family: arial;
}

</style>
</head>
<body bgcolor="#f0f0f0">
<div id="header">
<?php
include('login_top.php');
?>
</div>
<?php
include('menu.php');
?> 

<div id="body">
<div id="container">
<span id="sep">
<div id="mainContent">
<div>
	<h2>Binary Tree in action</h2>
	<table>
		<tr><td>Vertical Space:</td><td><input type="text" id="vSpace" value="10"/></td></tr>
		<tr><td>Horizontal Space:</td><td><input type="text" id="hSpace" value="50"/></td></tr>
		<tr><td>Color:</td><td><input type="text" id="color" value="#000000"/></td></tr>
		<tr><td>Stroke:</td><td><input type="text" id="stroke" value="2"/></td></tr>
	
		<tr><td>Border width:</td><td><input type="text" id="border" value="2"/></td></tr>
		<tr><td>Flip:</td><td><input type="checkbox" id="flip"/></td></tr>
		<tr><td colspan='2' align='center'><fieldset><legend>Orientation</legend><input id="horizontal" type="radio" name="orientation" 			checked="checked"/>Horizontal
		<br/><input type="radio" name="orientation"/>Vertical</fieldset></td></tr>
		<tr><td colspan='2' align='center'><button onclick="redraw();">Go!</button></td></tr>
	</table>
	<div id="treeDiv" style="overflow: hidden; height: 10px; border-style: solid; border-width: 3px; border-color: #000000;">
		<div style="border-style: inset;" id="box1">
			<span>Box1</span>

		</div>
		<div style="border-style: inset;">
			<span>Box2</span>
		</div>
		<div style="border-style: inset;">
			<span>Box3</span>
		</div>
		<div style="border-style: inset;">
	
			<span>Box4</span>
		</div>
		<div style="border-style: inset;">
			<span>Box5</span>
		</div>
		<div style="border-style: inset;">
			<span>Box6</span>

		</div>
		<div style="border-style: inset;">
			<span>Box7</span>
		</div>
		<div style="border-style: inset;">
			<span>Box8</span>
		</div>
		<div style="border-style: inset;">
	
			<span>Box9</span>
		</div>
		<div style="border-style: inset;">
			<span>Box10<br/></span>
		</div>
		<div style="border-style: inset;">
			<span>Box11</span>
	
		</div>
		<div style="border-style: inset;">
			<span>Box12</span>
		</div>
		<div style="border-style: inset;">
			<span>Box13</span>
		</div>
		<div style="border-style: inset;">

			<span>Box14</span>
		</div>
		<div style="border-style: inset;">
			<span>Box15</span>
		</div>
	</div>
</div>
 </span> 
</div>
<br class="clearfloat" />
<div id="footer">
    <p></p>
 </div>
</div>
</div>
</body>
</html>

I cannot test and understand your code for now but what do you mean by "down the tree"?

Hi, by "down line tree" I define the tree like the following

root
child01 child02
child03 child04 child05 child06
child08 child07

root
     child01             child02
child03 child04 child05 child06
child08                         child07

Maybe I didn’t understand something correctly. Is it a self referenced table? For example a typical self referenced table has ID and PARENT_ID so you can make a tree of “childs” a record has. In your table (if you provide the SHOW TABLE result would be better) -
[ Mem_id, Sponsor_id, Spill_id, Spill_Hand(L/R), Date_of_joining, lft, rgt ] I can’t understand what is the equivalent to the PARENT_ID I described. If you provide that also there are many ways of how to process the data in order to prepare them for view layer. Maybe the most common programming in PHP could be a multidimensional array.

Wow!!! I didn’t know that there was such thing out there. ID is something that doesn’t affects from historical changes. You can make a self referenced table with value as the ID as the example that you are mentioning but this is really makes things more complex then simplifying. For example if you change the value of one row you should also change the values of all the child’s rows and many-many others.

Hi,
mschroeder is right. I am using MPTT (Modified Preorder Tree Traversal). I have seen that example in sitepoint. But don't you think that it will be a very slow process if my data size grows to 10's of thousands.


jkon, you are rigth. I am using a self referenced table. And I am working on a spillover binary tree mechanise. Where one root can have more than two child, the extra child will be placed under any child of the root.

The real question is, how much reading vs writing happens with your tree structure, with MPTT pulling data is very fast and you take a performance hit on the writes/updates as this requires touching a larger number of records. Where as adjacency takes its performance hit on read operations and is much faster with inserts/updates.

MPTT has no issues dealing with more than two children either. What is the requirement for your tree structure to be a binary tree (left & right children)? Your table as defined seems to be a mixture of adjacency and MPTT.

root
      lvl-1(l)                            lvl-1(r)
 lvl-2(L1)     lvl-2(L1)          lvl-2(L2)     lvl-2(R2)

the red coloured nodes are child of root. As I am using a b-tree format to show the hierarchy that's why my MPTT is a b-tree. Coz the system demands. And that's why my table is also kind of mixture of MPTT and adjacency.

obviously reading will be much more w.r.t writing. but initially writing will be on the high side.

Hello Guys, Am new Here was hoping any one could help me with MLM Binary Script. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.