i have table like this
id(AI) user_id parent_user_id zone_id
1 8 0 0
2 8_L 8 L
3 8_R 8 R
and so on i want to display this as binary tree,a nd i use recursive function.,but it seems like it is not given the correct put
code
<div id='all' style='width: 250px;' align="center">8
<?php
//ChildNode(1);
function ChildNode($id)
{
global $wpdb;
$prefix=$wpdb->prefix;
$check_parent_node= $wpdb->get_results( $wpdb->prepare("SELECT * FROM ".$prefix."user_reference WHERE parent_user_id =".$id." LIMIT 2" ));
$user_count = $wpdb->get_var( "SELECT * FROM ".$prefix."user_reference WHERE parent_user_id =".$id." LIMIT 2" );
//SELECT * FROM ".$prefix."user_reference WHERE parent_user_id =".$id." LIMIT 2
//var_dump($user_count);
if($user_count>0)
{
echo "<div>";
foreach($check_parent_node as $chkpn)
{
if($chkpn->zone_id == 'L')
{
echo "<div id='left'style='float:left'>";
echo $chkpn->user_id ."   ";
}
else
{
echo "<div id='rigth' style='float:right'>";
echo "   ".$chkpn->user_id;
}
ChildNode($chkpn->user_id);
echo "</div>";
}
echo "</div>";
}
}
global $wpdb;
$prefix=$wpdb->prefix;
$user_parent_ids = $wpdb->get_results( $wpdb->prepare("SELECT * FROM wp_user_reference " ));
$parent_ids_array;
$count=0;
foreach($user_parent_ids as $urd)
{
$parent_ids_array[$count]=$urd->parent_user_id;
$count++;
}
$unique_parent_ids_array = array_unique($parent_ids_array);
foreach($unique_parent_ids_array as $upa)
{
if($upa!=0){
ChildNode($upa);
//echo "<br>".$upa."<br>";
}
}
?>
and this is the out put im getting
8
8_L 8_R
23_L 23_R
24_L 24_R
25_L 25_R
26_R26_L
27_L 27_R
28_L 28_R
29_L 29_R
30_L 30_R
31_L 31_R
32_L 32_R