I am building my tree view. I am facing a problem to arrange data from SQL query browser database to insert data into the Treeview with PHP. When I pick up data from the database into my treeview, it shows me many duplicate data into my treeview. Another problem is how to change style in the treeview? Hope someone can help me to check which part I get wrong. Thanks.
Below is my coding:
<div class="row-fluid">
<!-- block -->
<div class="block">
<div class="block-content collapse in">
<div class="span6">
<?php
$sql="select * from level_tree lt JOIN users u ON lt.user_id = u.id where lt.referal_id =". $user_id;
$query=mysql_query($sql);
if(mysql_num_rows($query)>0){
$select_name = 'SELECT * FROM users WHERE id = ' . $user_id;
$query_select = db_conn_select($select_name);
foreach($query_select as $rs_select) {
$name = $rs_select['name'];
$email = $rs_select['email'];
}
?>
<div id="jstree">
<ul>
<li><?php echo $name. '('.$email.')' ?></li>
<ul>
<?php
while($rs=mysql_fetch_array($query)){
echo "<li>".$rs['name']." (".$rs['email'].")";
downline_list($rs['id']);
echo "</li>";
}
?>
</div>
<?php
}else{
echo "No downline";
}
function downline_list($id){
$sql="select * from level_tree lt JOIN users u ON lt.user_id = u.id where lt.referal_id =".$id;
$query=mysql_query($sql);
if(mysql_num_rows($query)){
echo "<ul>";
while($rs=mysql_fetch_array($query)){
echo "<li>".$rs['name']." (".$rs['email'].")";
downline_list($rs['id']);
echo "</li>";
}
echo "</ul>";
}
}
?>
</ul></div>
</div>
</div>
<!-- /block -->
</div>
<script src="plugins/jstree/dist/jquery-1.10.2.min.js"></script>
<link rel="stylesheet" href="plugins/jstree/dist/themes/default/style.min.css" />
<script src="plugins/jstree/dist/jstree.min.js"></script>
<script>
$(function () {
// 6 create an instance when the DOM is ready
$('#jstree').bind("ready.jstree", function () {
$('#jstree').jstree('open_all');
}).jstree();
});
</script>
<style type="text/css">
.jstree li > a > .jstree-icon { display:none !important; }
</style>
I want to get data from database, I have 2 table ("users" and "level_tree") in my database below is my database information:
Table "users"(In this table I am using name is "developer2" account, so the top 1 in the tree name is select developer2, and this table I want to get column "name" and "email" data show in my treeview. This table"referal_id" number means under which person "name". For example: In this table example if name "tong" "referal_id" is "8", So that, name"tong" upline is "Ooi Thong Bee", because name "Ooi Thong Bee" "id" is "8". "referal_id" is get from "id" ):
Table "level_tree"(In this table, "referal_id" = 3 means that is under my account name"developer2", because in the table "users", name"developer2" is "id = 3". Column "level" means that see the "user_id" stand which level):
The output show me like the below picture:
Actually I want the output data arrange and treeview style in the treeview same like below picture: