This example is using AJAX and PHP with a MYSQL database to show the Left and Right Tree. I already use this code on the network business companies where they have a member and the member should have to create his other sub member on his Left or right and other member as well.
Also i have enclose "mysql database connectivity class version 1.3" with new function
Hope you like this example, see attached file above.
tree1.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Tree Structure </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" src="scripts1.js"></script>
</head>
<body>
<?php
include ("include/host_conf.php");
include ("include/mysql.lib.php");
$obj=new connect();
include ("functions.php");
$sn=1; // You can change this value to see the tree related to this member
if(empty($sn)) {
$sn=1;
}
$sql="SELECT * FROM tbl_tree WHERE id=$sn";
main_box($sql);
?>
</body>
</html>
scripts1.js
var xmlHttp
var id
function showHint(str, div){
if (str.length > 0){
var url=str
id = div
function stateChanged() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById(id).innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject(handler){
var objXmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0){
alert("This example doesn't work in Opera")
return
}
if (navigator.userAgent.indexOf("MSIE")>=0){
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
strName="Microsoft.XMLHTTP"
}
try{
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler
return objXmlHttp
}
catch(e){
alert("Error. Scripting for ActiveX might be disabled")
return
}
}
if (navigator.userAgent.indexOf("Mozilla")>=0){
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler
return objXmlHttp
}
}
functions.php
<?php
/*
This is the main file of this tree project
here in this file the DIV is created according to the member ID and it is concanate to the placement_type as well
for eg if the member id is 1 and the placement type is L then the div id = 1L
This page is called from the Tree1.php for first time
and it will show the below table with 2 respected links L and R (only if he had a sub member)
and when click on this 2 links they will call javascript function named "showhint" with URL and the ID of the member and DIV ID (1L or 1R)
well this showhint function is in script1.js file it will call the ajaxreturn.php file along with URL and the Div ID
<?php
include ("include/host_conf.php");
include ("include/mysql.lib.php");
$obj=new connect();
include("functions.php");
$sql="SELECT * FROM tbl_tree WHERE parent_id=".$_GET['id']." AND placement_type='".$_GET['lr']."'";
main_box($sql);
?>
mysql.lib.php
<?php
/*******************
Mr. Suraj Thapaliya
PHP Programmer
http://www.surajthapaliya.com.np
version 1.3
*/
class connect
{
var $Host = C_DB_HOST; // Hostname of our MySQL server
var $Database = C_DB_NAME; // Logical database name on that server
var $User = C_DB_USER; // Database user
var $Password = C_DB_PASS; // Database user's password
var $Link_ID = 0; // Result of mysql_connect()
var $Query_ID = 0; // Result of most recent mysql_query()
var $Record = array(); // Current mysql_fetch_array()-result
var $Row; // Current row number
var $Errno = 0; // Error state of query
var $Error = "";