Jump to content

How to count and display additions to a tree in between date


Recommended Posts

I made the basic function to count the number of left count and right count. However now i need to display then number of additions to a tree according to their joining date. I stuck here. can someone please show me the logic to do this ?


I know i need to use UNION for sql because date of joining and tree structure are in different tables.


Sql tables-


Member table -(doj is date of join)



Tree table-



Basic Code-

function tree_count($node)   //Function to calculate count;$node is first lchild or first rchild.
    $sql = "SELECT lchild,rchild FROM tree WHERE parent = '".$node."'" ;
// $sql = "SELECT lchild,rchild FROM tree WHERE parent = '".$node."'             should i do something like this ?
//           UNION SELECT member_id FROM member WHERE id_sponsor=".$node." AND doj BETWEEN '".$from."' AND '".$to."'" ;
    $execsql = mysql_query($sql);
    $array = mysql_fetch_array($execsql);
      $count += tree_count($array['lchild']);
       $count += tree_count($array['rchild']);
    $totalcount = 1 + $count;
    return $totalcount;



Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.