shiningsina Posted November 6, 2008 Share Posted November 6, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/131658-multiple-count/ Share on other sites More sharing options...
DeanWhitehouse Posted November 6, 2008 Share Posted November 6, 2008 I think no one is answering because there aren't code tags and its long and boring to read. Try summing it up with vital points and the mentioned code. Quote Link to comment https://forums.phpfreaks.com/topic/131658-multiple-count/#findComment-683875 Share on other sites More sharing options...
Imad Posted November 6, 2008 Share Posted November 6, 2008 Instead of putting or, put an and. It will count id1 AND id2, etc. Quote Link to comment https://forums.phpfreaks.com/topic/131658-multiple-count/#findComment-683877 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.