Jump to content

Recommended Posts

I'm currently trying to work on a MLM application where somebody brings 5 persons and the chain continues on as each person brings 5 persons. I have succeeded in creating a database that recognizes generations using the following code

database:

CREATE TABLE `downline` (

  `member_id` varchar(11) NOT NULL default '',

  `parent_id1` varchar(11) default NULL,

  `parent_id2` varchar(11) default NULL,

  `parent_id3` varchar(11) default NULL,

  `parent_id4` varchar(11) default NULL,

  `parent_id5` varchar(11) default NULL,

  `parent_id6` varchar(11) default NULL,

  `parent_id7` varchar(11) default NULL,

  `parent_id8` varchar(11) default NULL,

  `parent_id9` varchar(11) default NULL,

  `parent_id10` varchar(11) default NULL,

  `parent_id11` varchar(11) default NULL,

  `parent_id12` varchar(11) default NULL,

  `parent_id13` varchar(11) default NULL,

  `parent_id14` varchar(11) default NULL,

  `parent_id15` varchar(11) default NULL,

  `parent_id16` varchar(11) default NULL,

  `parent_id17` varchar(11) default NULL,

  `parent_id18` varchar(11) default NULL,

  `parent_id19` varchar(11) default NULL,

  `parent_id20` varchar(11) default NULL,

  `created` datetime NOT NULL default '0000-00-00 00:00:00',

  PRIMARY KEY  (`member_id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

parent_1d1 takes care of the 1st generation (5 downlines), parent_id2 takes care of 2nd generation(25 downlines belonging to the 1st generation) and the chain continues. I counted the total number of downlines of each member by using:

<td><strong>Sponsor</strong></td>

          <td><strong>Total Downlines</strong></td>

          <!--<td><strong>Total Downlines</strong></td>-->

        </tr>

        <?php

$query  = "SELECT member_id FROM downline";

$result1 = mysql_query($query);

 

while($row = mysql_fetch_array($result1))

{

$member_id=$row[member_id];

 

 

    $result=mysql_query("SELECT COUNT(member_id) AS downlines FROM downline WHERE parent_id1='$member_id' or parent_id2='$member_id' or parent_id3='$member_id' or parent_id4='$member_id' or parent_id5='$member_id' or parent_id6='$member_id' or parent_id7='$member_id' or parent_id8='$member_id' or parent_id9='$member_id' or parent_id10='$member_id' or parent_id11='$member_id' or parent_id12='$member_id' or parent_id13='$member_id' or parent_id14='$member_id' or parent_id15='$member_id' or parent_id16='$member_id' or parent_id17='$member_id' or parent_id18='$member_id' or parent_id19='$member_id' or parent_id20='$member_id'");

  if(mysql_num_rows($result)>0):

while($resultarray=mysql_fetch_array($result)):

  ?>

        <tr>

          <td><?php echo $row['member_id'];?></td>

          <td><?php echo $resultarray['downlines']; ?></td>

          <!--<td> </td>-->

        </tr>

        <?php

  endwhile;

  endif;

  }

 

I don't know how to count parent_id1, parent_id2.......,parentid15, etc for each member_id so that one could know the generations that have completed their cycles.

Link to comment
https://forums.phpfreaks.com/topic/131658-multiple-count/
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.