从PHP MySQL中的转介系统中跳过非活动的赞助商ID

时间:2018-05-13 15:12:31

标签: php mysql

我有一个推荐系统数据库,用户可以在每个级别获得最高6级的佣金。但是我省略了不活动的用户而不是上去。我的脚本为每个活动或不活动的用户提供服务。我的PHP,MySQL代码如下

   $eredm= mysqli_query($conn,"
SELECT u1.sponsorid AS referral1
     , u2.sponsorid AS referral2
     , u3.sponsorid AS referral3
     , u4.sponsorid AS referral4
     , u5.sponsorid AS referral5
     , u6.sponsorid AS referral6
     , u7.sponsorid AS referral7
  FROM users AS u1 
      JOIN users As u2 
       ON u1.sponsorid = u2.username
      JOIN users As u3 
       ON u2.sponsorid = u3.username 
      JOIN users As u4 
       ON u3.sponsorid = u4.username 
      JOIN users As u5 
       ON u4.sponsorid = u5.username 
      JOIN users As u6 
       ON u5.sponsorid = u6.username 
      JOIN users As u7 
       ON u6.sponsorid = u7.username 
      JOIN users As u8 
       ON u7.sponsorid = u8.username
     WHERE u1.username = '$userid'
 ");
     $rows= mysqli_fetch_array($eredm);

     $referrer1 = $rows['referral1'];
     $referrer2 = $rows['referral2'];
     $referrer3 = $rows['referral3'];
     $referrer4 = $rows['referral4'];
     $referrer5 = $rows['referral5'];
     $referrer6 = $rows['referral6'];
     $referrer7 = $rows['referral7'];

    $refpc[1]=$refpc1; $refpc[2]=$refpc2; $refpc[3]=$refpc3; 
    $refpc[4]=$refpc4; $refpc[5]=$refpc5; 
    $refpc[6]=$refpc6; $refpc[7]=$refpc7;  

    $cref[1]=$referrer1; $cref[2]=$referrer2; $cref[3]=$referrer3; 
    $cref[4]=$referrer4; $cref[5]=$referrer5; 
    $cref[6]=$referrer6; $cref[7]=$referrer7;  

    $i=1;
    while($i<=$rlevels){

     if (!($cref[$i]=='_')){
     $curcomission = ($invest_to_add/100)*$refpc[$i];
     $curref = $cref[$i];
     $eredm = mysqli_query($conn,"UPDATE users SET 
     earned=earned+$curcomission 
      WHERE username='$curref'");
     $ma = date("Y-m-d");
     $eredm = mysqli_query($conn,"INSERT INTO 
     credits(s_date,s_reason,s_amount,s_user,s_type) VALUES('$ma','Ref. 
     comission from $userid',$curcomission,'$curref',1)") or 
     die(mysqli_error());
      }
     $i++
     }

问题出在哪里。我该怎么办?

0 个答案:

没有答案