Jump to content

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


Nuv

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)

member.PNG

 

Tree table-

tree.png

 

Basic Code-

<?php 
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);
    
    if(!empty($array['lchild']))
    {
      $count += tree_count($array['lchild']);
      
    } 
    if(!empty($array['rchild']))
    {
       $count += tree_count($array['rchild']);
       
    }
    
    $totalcount = 1 + $count;
    return $totalcount;
    
  }  
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.