The Ajax Tree view class fetches data from a db for the requested parent category id. The data is then stored in an array and converted into JSON (Javascript Object Notation) format. This format is then used by JavaScript for populating tree view.
AjaxTreeview class fetches data from a datatable for the requested parent category id. The data is then stored in array and converted into JSON format. This JSON format is then used by javascript code for populating tree view. JSON ( Javascript Object Notation ) is used as transitional language though XML based version is also available. JSON is used to make processing fast as compared to XML. For component AjaxTreeview JSON support must be available on server side. The component is multibrowser, cross database, cross server side language, fast, flexible and is very easy to implement.
For Installaton ..
1. Run db.sql file on your local or remote database..
2. Change the configuration settings for host, database name, username and password inside services.php.
3. Run index.php file using php compatible web server.
About myself:
I am a PHP programmer working as Sr. Developer in Classic Informatics.
Please rate this class If you find it useful. Please feel free to contact me for queries related to this class. I would feel gratefull if i can sort out your issues related to PHP.
Thanks in advance.
Neeraj Thakur
Sr. Developer
Emails:
neeraj_th@yahoo.com
neerajth@gmail.com
index.php
<head>
<link rel="stylesheet" href="css.css" type="text/css">
</head>
<body>
<div id="loadingbox"></div>
<script language="javascript" type="text/javascript" src="ajax.js"></script>
<script language="javascript" type="text/javascript" src="tree.js"></script>
<script language="JavaScript">
var UI = new Object();
UI.expand = '+';
UI.collapse = '-';
function getData(id)
{
alert("Get Data for Id : " + id);
}
var Page = new Object();
Page.width;
Page.height;
Page.top;
class AjaxTreeview
{
public function AjaxTreeview()
{
// Make the connnection and then select the database.
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );
mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );
$this->table = "tblcategories";
}
function dbConnect()
{
DEFINE ('LINK', mysql_connect (DB_HOST, DB_USER, DB_PASSWORD));
}
public function getCatList($catid)
{
$this->dbConnect();
$query = "SELECT * FROM {$this->table} where pid = {$catid} ORDER BY id asc";
$result = mysql_db_query (DB_NAME, $query, LINK);
$arr = array();
$i = 0;
while( $rec = mysql_fetch_array($result) )
{
$arr[$i]['id'] = $rec['id'];
$arr[$i]['name'] = $rec['name'];
$arr[$i]['pid'] = $rec['pid'];
$i ++ ;
}
return $arr;
}
}
?>
I am bit new to AJAX. I have tried your code for tree view. Its
working wonderfully. My question is, when there is some error in
database like wrong password, etc.. it does not display the error
message.
How to display error message?
Regards,
Nitesh
Josh Woods wrote :1880
I cannot get this to work for me. I've changed the db
settings and everything as instructed and no error
message, no nothing. Any ideas? Also I'm running this on
xampp on a flash drive.