嵌套条件的多级营销逻辑问题

时间:2016-04-03 11:33:19

标签: php mysql

我在多层次营销中遇到逻辑问题。

有关详细说明,请参阅以下图片。

MLM

上面的逻辑将工作到10级。

考虑以下例子。

  1. 假设我已注册为新用户且没有任何赞助商代码。然后我将成为root用户。我的赞助商ID是123。

  2. 然后通过输入我的赞助商ID(即123)注册新用户,然后他将成为用户123的第一个孩子。一个用户的最大子女数为4。 新用户赞助商ID为A123。

  3. 一旦用户123的子计数超过4.并且新用户再次进入赞助商ID为123,那么他将被注册到赞助商ID为A123的第一个孩子。

  4. 同样,赞助商ID 123的新注册将在第二个孩子的参考下注册。

  5. 我写的逻辑再次转向123的第一个孩子,只是迭代不能按我的意愿工作。

    我不是要求整个代码只是让我知道我错在哪里。

    表格结构:

    CREATE TABLE `users` (
      `id` int(11) NOT NULL,
      `username` varchar(200) NOT NULL,
      `full_name` varchar(200) NOT NULL,
      `email` varchar(200) NOT NULL,
      `mobile` varchar(200) NOT NULL,
      `sponsor_id` varchar(200) NOT NULL,
      `unique_code` varchar(200) NOT NULL,
      `code_entered` varchar(200) NOT NULL,
      `sponsor_count` int(200) NOT NULL,
      `direct` varchar(200) NOT NULL,
      `direct_count` int(11) NOT NULL,
      `serial_no` varchar(200) NOT NULL,
      `package_amount` varchar(200) NOT NULL,
      `password` varchar(200) NOT NULL,
      `birthday` varchar(200) NOT NULL,
      `pancard_no` varchar(200) NOT NULL,
      `city` varchar(200) NOT NULL,
      `address` text NOT NULL,
      `last_login` varchar(200) NOT NULL,
      `last_login_Ip` varchar(200) NOT NULL,
      `date` varchar(200) NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `users`
    --
    
    INSERT INTO `users` (`id`, `username`, `full_name`, `email`, `mobile`, `sponsor_id`, `unique_code`, `code_entered`, `sponsor_count`, `direct`, `direct_count`, `serial_no`, `package_amount`, `password`, `birthday`, `pancard_no`, `city`, `address`, `last_login`, `last_login_Ip`, `date`) VALUES
    (1, 'SA', 'MK', 'MK@gmail.com', '9702242036', '66666666', '64384703', '', 4, '', 53, '13212', '400.00', '123', '11/11/1994', '15155155155', 'Mumbai', 'Ghatkopar', 'April 2 2016', '58.146.119.92', 'March 17 2016'),
    (38, 'jkjdkjskdk', 't', 'jkdjskjkjk', 'salsaj', '64384703', '10404315', '64384703', 4, '64384703', 0, '1312', '400.00', 'jdjsjkdjskdjs', '', '', '', '', '', '', 'March 31 2016'),
    (39, 'dsnn', 's', 'ndksnd', 'saksnkan', '64384703', '69669736', '64384703', 4, '64384703', 0, 'samksa', '400.00', 'njnsjnj', '', '', '', '', '', '', 'March 31 2016'),
    (40, 'jdsjjaj', 's', 'jkjsjaksj', 'sakskajk', '64384703', '88455053', '64384703', 4, '64384703', 0, '425545454545', '400.00', 'jkdsjkd', '', '', '', '', '', '', 'March 31 2016'),
    (41, 'ndsjnd', 'Sumit', '45sansjnaj', '7577545', '64384703', '15397510', '64384703', 4, '64384703', 0, '23232323', '400.00', 'njnsjndjn', '', '', '', '', '', '', 'March 31 2016'),
    (75, 'WFwf', 'adWADq', 'fwef', 'wqfWFw', '15397510', '36171300', '64384703', 0, '64384703', 0, 'dWADwdAD', '400.00', 'FwfWF', '', '', '', '', '', '', 'March 31 2016'),
    (74, 'CAscSAC', 'ASCC39502728', 'CASC', 'CASCAS', '88455053', '69828189', '64384703', 0, '64384703', 0, 'ACAsc', '400.00', 'ASCASCAS', '', '', '', '', '', '', 'March 31 2016'),
    (73, 'caSCASCA', 'ASCASCA', 'CSAc', 'sCSAC', '69669736', '17947094', '64384703', 0, '64384703', 0, 'ASDAd', '400.00', 'Csacasc', '', '', '', '', '', '', 'March 31 2016'),
    (60, 'fDwsdw', 'SCSFSF', 'wdwD', 'wedwedw', '10404315', '47797754', '64384703', 1, '64384703', 0, 'WDWDWD', '400.00', 'wfdWFF', '', '', '', '', '', '', 'March 31 2016'),
    (61, 'Sacsc', 'SDSdCD', 'csc', 'ScScs', '69669736', '06965959', '64384703', 0, '64384703', 0, 'SFSDASD', '400.00', 'scscsc', '', '', '', '', '', '', 'March 31 2016'),
    (62, 'AsCsc', 'asCAsca', 'AscascAs', 'sacasAC', '88455053', '80778770', '64384703', 0, '64384703', 0, 'AsCascS', '400.00', 'AScasXas', '', '', '', '', '', '', 'March 31 2016'),
    (63, 'CaScasc', 'ASCascScaS', 'CascacaS', 'ASCAS', '15397510', '61309698', '64384703', 0, '64384703', 0, 'sCFasfC', '400.00', 'acascas', '', '', '', '', '', '', 'March 31 2016'),
    (64, 'scascACS', 'asCASc', 'CASCSCa', 'casCS', '10404315', '39502728', '64384703', 1, '64384703', 0, 'asdaSDSD', '400.00', 'cASCAS', '', '', '', '', '', '', 'March 31 2016'),
    (65, 'scasc', 'dxadascd', 'ascasca', 'scascasc', '69669736', '15508065', '64384703', 0, '64384703', 0, 'ADADada', '400.00', 'casc', '', '', '', '', '', '', 'March 31 2016'),
    (66, 'csdvsdvs', 'asdascsc', 'scscs', 'scsc', '88455053', '96194063', '64384703', 0, '64384703', 0, 'sFf', '400.00', 'dvdsvsd', '', '', '', '', '', '', 'March 31 2016'),
    (67, 'ASASSC', 'ascsac', 'aScS', 'ascadsa', '15397510', '79804063', '64384703', 0, '64384703', 0, 'ssSCFa', '400.00', 'ACASDA', '', '', '', '', '', '', 'March 31 2016'),
    (68, 'acasC', 'acascasc', 'asca', 'ascasc', '10404315', '15145419', '64384703', 1, '64384703', 0, 'AWDacac', '400.00', 'ascsca', '', '', '', '', '', '', 'March 31 2016'),
    (69, 'aA', 'aAFawf', 'afaf', 'asdaSF', '69669736', '48166652', '64384703', 0, '64384703', 0, 'aSDAWDAD', '400.00', 'adsd', '', '', '', '', '', '', 'March 31 2016'),
    (70, 'FAFasf', 'sfSFS', 'FSFSFS', 'DSFSDFS', '88455053', '74124082', '64384703', 0, '64384703', 0, 'SFsf', '400.00', 'Faf', '', '', '', '', '', '', 'March 31 2016'),
    (71, 'ScScs', 'SCC', 'scSC', 'scscsC', '15397510', '65224240', '64384703', 0, '64384703', 0, 'sScScs', '400.00', 'csc', '', '', '', '', '', '', 'March 31 2016'),
    (72, 'Acsac', 'SACAcas', 'Asc', 'cascASC', '10404315', '13703218', '64384703', 1, '64384703', 0, 'ASCASc', '400.00', 'AscAsc', '', '', '', '', '', '', 'March 31 2016'),
    (77, 'scdv', 'sdvdsvs', 'sDvsdv', 'sD', '39502728', '87098579', '64384703', 0, '64384703', 0, 'sdadscsdv', '400.00', 'svdsvsd', '', '', '', '', '', '', 'March 31 2016'),
    (78, 'asfsadf', 'avsdvads', 'fsdfdsaf', 'ssadv', '15145419', '82251755', '64384703', 0, '64384703', 0, 'asfasf', '400.00', 'safsadf', '', '', '', '', '', '', 'March 31 2016'),
    (79, 'sFf', 'ff', 'SFs', 'FsfSF', '13703218', '09815392', '64384703', 0, '64384703', 0, 'fFEF', '400.00', 'sfsf', '', '', '', '', '', '', 'March 31 2016'),
    (82, 'SFDSADFD', 'ASDFSADF', 'AFAFASFD', 'FSFASF', '15145419', '62181227', '64384703', 0, '64384703', 0, 'SFSDSF', '400.00', 'SFSF', '', '', '', '', '', '', 'April 1 2016'),
    (83, 'KPNKOPN', 'PKPKOPOKP', 'KOPKO', 'OPKOP', '13703218', '37114007', '64384703', 0, '64384703', 0, 'NKONOP;N', '400.00', 'NKPNKOP', '', '', '', '', '', '', 'April 1 2016'),
    (86, 'KOPKNOPN', 'PKNPKNPKN', 'PKPKO', 'PKOPKOP', '15145419', '95262805', '64384703', 0, '64384703', 0, 'NKPNKOPN', '400.00', 'KONPNKO', '', '', '', '', '', '', 'April 1 2016'),
    (87, 'P;NP', 'ONPPNP', 'NKOPKOP', 'NPOKP', '13703218', '68382470', '64384703', 0, '64384703', 0, 'JINJNP', '400.00', 'PNJPNPN', '', '', '', '', '', '', 'April 1 2016'),
    (90, 'HFHFG', 'TFHFH', 'HFGHHG', 'FHFCHFCH', '15145419', '24886528', '64384703', 0, '64384703', 0, 'HTFHTGHC', '400.00', 'HGFHXFH', '', '', '', '', '', '', 'April 1 2016'),
    (91, 'XFHXFTH', 'FTHFH', 'HFTHFTXHFX', 'HXFHXFT', '13703218', '58477780', '64384703', 0, '64384703', 0, 'TFHTFHTFH', '400.00', 'HGXHH', '', '', '', '', '', '', 'April 1 2016');
    

    CODE:

    <?php
    INCLUDE('db.php');
    
    
            function min_count($sponsor_id){
    
                    $select11 = mysql_query("SELECT MIN(sponsor_count) as count FROM users WHERE sponsor_id='$sponsor_id'");    
                    $rows11 = mysql_fetch_assoc($select11);             
                    $count_n1 =  $rows11['count'];
    
                    return $count_n1;
    
    
            }
    
            function sponsor_count_name($sponsor_id){
    
                    $select111 = mysql_query("SELECT sponsor_count FROM users WHERE unique_code='$sponsor_id'");    
                    $rows111 = mysql_fetch_assoc($select111);               
                    $count_s =  $rows111['sponsor_count'];
    
                    return $count_s;
    
    
            }
    
            function id_check($sponsor_id){
    
                    $select111 = mysql_query("SELECT sponsor_count FROM users WHERE unique_code='$sponsor_id'");    
                    $rows111 = mysql_fetch_assoc($select111);               
                    $count_s =  $rows111['sponsor_count'];
    
                    return $count_s;
    
    
            }
    
    
    
            function sponsor_count($sponsor_id){
    
    
                    echo "<font color='red'>Sponsor_id : $sponsor_id</font><br/>";
                    $min_count =  min_count($sponsor_id);
                    //min_count  = 4
    
    
                    // its full 4
    
                    $sponsor_count_u = sponsor_count_name($sponsor_id);
                    // sponsor_count_u = 4  
    
                    echo "<font color='red'>Min Count : $min_count</font><br/><hr/>";
    
    
    
                    if($sponsor_count_u < 4){
    
    
                    echo "<font color='red'>$sponsor_id</font><br/>";
    
                    }else{
    
                function check_count($min_count,$sponsor_id){   
    
                    if($min_count < 4 ){
    
                        $select11 = mysql_query("SELECT unique_code FROM users WHERE sponsor_count='$min_count' AND sponsor_id='$sponsor_id'"); 
                        $rows11 = mysql_fetch_assoc($select11);         
                        $sponsor_id = $rows11['unique_code'];
    
                            return   $sponsor_id; 
    
    
                    }else{
    
                        $select1 = mysql_query("SELECT unique_code FROM users WHERE sponsor_id='$sponsor_id'"); 
    
                            while($rows1 = mysql_fetch_assoc($select1)){
                            $sponsor_id = $rows1['unique_code'];
    
                            echo "<font color='green'> <b>$sponsor_id</font> </b>&nbsp;";
    
                            $sponsor_count_u = sponsor_count_name($sponsor_id); 
                            echo "<font color='red'>Min Count: $sponsor_count_u</font><br/>";
    
    
    
    
    
                            $select11 = mysql_query("SELECT unique_code FROM users WHERE sponsor_id='$sponsor_id'");    
    
                            while($rows11 = mysql_fetch_array($select11)){
                            $sponsor_id1 = $rows11['unique_code'];
    
                            echo "<font color='blue'> <b>$sponsor_id1</font> </b>&nbsp;";
    
                            $min_count1 = sponsor_count_name($sponsor_id1); 
    
                            echo "$min_count1<br/>";
    
    
                            //$min_array = array($min_count);
    
    
                            //  turn check_count($min_count,$sponsor_id1);
    
    
    
                            }
    
    
                            }
    
                        }
                }
    
                }
    
    
    
                return check_count($min_count,$sponsor_id);
    
    
    
            }
    
    
                echo  sponsor_count(64384703);
    
    
    
    ?>
    

0 个答案:

没有答案