hey, i am newbie , need help in creating a php script which can count the no. of members in a binary downline, the fields in the database are like this:
id name ref_id
1 kundan 0
2 rahul 1
3 deepak 2
4 chandan 2
5 avi 3
6 ajit 3
7 punit 4
8 sunil 4

the tree will grow to abt ten thousands of members, i trying to work it out by using recursive functions(using a while loop), and i am able to print the downline as a list, but the problem is that i've to calculate the no. of members. can anyone help...

    Is this what your looking for

    <?php
      echo ' <table border="1" width="95%" cellpadding="5" cellspacing="12">
    <tr>
    <td align="center"><b>Count</b></td>
    <td align="center"><b>ID</b></td>
    <td align="center"><b>Name</b></td>
    <td align="center"><b>Ref ID</b></td>
    
    </tr>
    
    ';
    
      $query = ("SELECT id, name, ref_id  FROM TABLENAME ");
    
      $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    
      $i = 0;
    
      while ($line = mysql_fetch_row($result))
          {
          echo '<tr>';
          echo '<td align="center">' . $i++ . '</td>';
          echo '<td align="center">' . $line['0'] . '</td>';
          echo '<td align="center">' . $line['1'] . '</td>';
          echo '<td align="center">' . $line['2'] . '</td>
    
    </tr>';
          }
      echo '</table>';
    ?>
    

      thank u 4 replying but this not exactly what i'm looking for.
      my code looks like this:

      <?php

      $i=10;// the list will show the downline for a member with id = 10
      prin($i);// calling function prin
      function prin($i) //definition
      {
      $id=$i;
      $q=mysql_query("select id from f2_users where up_id='$id'");
      while($r=mysql_fetch_row($q))
      {
      $i=$r[0];
      echo $i;
      echo "<br>";
      prin($i); // recursion
      }

      }
      ?>

      this code lets me print the id of any member so that we can see his downline. It works in a recursive manner. All i want to do is to count the no. of member s in one's downline.
      The code genrates the id no.s but does'nt count it. Add anything if you want , but plz get me this script working.. Thnx in advance...

        thanks again 4 replying, as i told u before , i am using recursion for this operation, mysql_num_rows() is working fine when i use it without recursion, but when calling function inside itself, the mysql_num_rows() generates a value , which changes each time the function calls itself, this way we get a series of strings at the end of each loop, all i want to do is to add all these strings (numbers) inside an array or a static variable , but don't know how to do it. I really appreciate your help...

        <?php

        $i=10;// the list will show the downline for a member with id = 10
        prin($i);// calling function prin
        function prin($i) //definition
        {
        $id=$i;
        $q=mysql_query("select id from f2_users where up_id='$id'");
        $count= mysql_num_rows($q);// gives new value each time
        while($r=mysql_fetch_row($q))
        {
        $i=$r[0];
        echo $i;
        echo "<br>";
        prin($i); // recursion
        }

        }
        ?>

          iamkundan;10958954 wrote:

          All i want to do is to count the no. of member s in one's downline.

          Maybe im misunderstanding but based on the quote and on the code if you echo $count then you will get the number of members that have been produced.

            Write a Reply...