Page 1 of 1

referral system help

Posted: Sun Aug 07, 2011 12:20 pm
by nite4000
I hope someone can help me here

i have a referral system that is 6 levels deep

the rates are as follows

level rates is 8%,5%,4%,3%,2%,and 1% of the deposit

so lets say user1 joins then refers user 2 and user 2 makes a depo then user 1 get 8% of the depo from user 2 and then if user 2 refers user3 then user 2 gets 8% and user 1 gets 5% of the depo from user 3 and so on

now my problem is I have got it to put the amounts in teh referral table HOWEVER i need to add the amounts to the right users account

Here is my code.

where you see 0.65 is me simualting a fake deposit so it will give commision.

I have echoed certain info but the last part at the bottom is the part i need help with , how do i get it to get the money to the right accounts

Code: Select all


// Add amount of deposit to processed_deposit field
$query = mysql_query("SELECT * FROM accounts")or die(mysql_error());

while($acct_info=mysql_fetch_array($query))
{
	echo "<br/>";
	print_r($acct_info);
	echo "<br/>";
	
	
//$dpuser=$mydeps["username"];
//$deposit=$mydeps["total_deposit"];

// getting the processed deposit
//$processed_deposit = $mydeps["processed_deposit"];
//$saving_deposit = $mydeps["total_deposit"];
//amount to process now
//$deposit2 = $deposit - $processed_deposit;
//$lrtotal = $_REQUEST['lr_amnt'];
// updating acount for future
$r=mysql_query("UPDATE accounts SET processed_deposit = '0.65' WHERE username='{$_SESSION['admin_user']}' LIMIT 1")or die(mysql_error());


}


//fiqure up the commision

  $q = mysql_query("SELECT * FROM referral_settings WHERE id='1'",$link) or die(mysql_error());
  $r_settings = mysql_fetch_array($q, MYSQL_ASSOC);
  @mysql_free_result($q);
echo "<br/>";
echo "<br/>";
echo 'Rate :'; echo $r_settings['top_level'];
echo "<br/>";
echo "<br/>";
//Commision precentages for each referel level
$commis_lvl1_prc = $r_settings['top_level']; //0.08;
$commis_lvl2_prc = $r_settings['level_2'];//0.05;
$commis_lvl3_prc = $r_settings['level_3'];//0.04; //$5 * 0.04 = 0.20
$commis_lvl4_prc = $r_settings['level_4'];//0.03;
$commis_lvl5_prc = $r_settings['level_5'];//0.02;
$commis_lvl6_prc = $r_settings['level_6'];//0.01;


  if ($level_6 == NULL){
        $commis_lvl_6=$commis_lvl6_prc * 0.65;
        }
        if ($level_5 == NULL){
        $commis_lvl_5=$commis_lvl5_prc * 0.65;
        }
        if ($level_4 == NULL){
        $commis_lvl_4=$commis_lvl4_prc * 0.65;
        }
        if ($level_3 == NULL){
        $commis_lvl_3=$commis_lvl3_prc * 0.65;
        }
        if ($level_2 == NULL){
        $commis_lvl_2=$commis_lvl2_prc * 0.65;
        }
        if ($referral == NULL){
        $commis_lvl_1=$commis_lvl1_prc * 0.65;

echo 'Top_level :';   echo  $commis_lvl_1;	echo 'to user1';	
echo "<br/>";
echo "<br/>";	
echo 'Level 2:';      echo $commis_lvl_2; echo 'to user2';	
echo "<br/>";
echo "<br/>";       
echo 'Level 3:';      echo $commis_lvl_3;	
echo "<br/>";
echo "<br/>";
echo 'Level 4:';      echo $commis_lvl_4;
echo "<br/>";
echo "<br/>";
echo 'Level 5:';      echo $commis_lvl_5;
echo "<br/>";
echo "<br/>";
echo 'Level 6:';      echo $commis_lvl_6;



 }


//Update accounts with the commision amount
$query2 = mysql_query("SELECT * FROM referrals WHERE username='{$_SESSION['admin_user']}'")or die(mysql_error());

while($ref_info=mysql_fetch_array($query2))
{

$earnuser=$ref_info["username"];
$ref = $ref_info['referral'];
$level_2=$ref_info["level_2"];
$level_3=$ref_info["level_3"];
$level_4=$ref_info["level_4"];
$level_5=$ref_info["level_5"];
$level_6=$ref_info["level_6"];
$commis_ear_1=$ref_info["commis_lvl_1"];
$commis_ear_2=$ref_info["commis_lvl_2"];
$commis_ear_3=$ref_info["commis_lvl_3"];
$commis_ear_4=$ref_info["commis_lvl_4"];
$commis_ear_5=$ref_info["commis_lvl_5"];
$commis_ear_6=$ref_info["commis_lvl_6"];




	    $r=mysql_query("UPDATE referrals SET commis_lvl_1='".$commis_lvl1_prc * 0.65."' WHERE referral = '$earnuser'")or die(mysql_error());
        $r=mysql_query("UPDATE referrals SET commis_lvl_2='".$commis_lvl2_prc * 0.65."' WHERE level_2 ='$earnuser'")or die(mysql_error());
        $r=mysql_query("UPDATE referrals SET commis_lvl_3='".$commis_lvl3_prc * 0.65."' WHERE level_3 ='$earnuser'")or die(mysql_error());
        $r=mysql_query("UPDATE referrals SET commis_lvl_4='".$commis_lvl4_prc * 0.65."' WHERE level_4 ='$earnuser'")or die(mysql_error());
        $r=mysql_query("UPDATE referrals SET commis_lvl_5='".$commis_lvl5_prc * 0.65."' WHERE level_5 ='$earnuser'")or die(mysql_error());
        $r=mysql_query("UPDATE referrals SET commis_lvl_6='".$commis_lvl6_prc * 0.65."' WHERE level_6 ='$earnuser'")or die(mysql_error());
$earned = $commis_lvl_1 + $commis_lvl_2 + $commis_lvl_3 + $commis_lvl_4 + $commis_lvl_5 + $commis_lvl_6;
echo "<br/>";
echo "<br/>";
echo $earned;
echo "<br/>";
echo "<br/>";
$query=mysql_query("UPDATE accounts SET acct_balance = acct_balance + '$earned',earned_total=earned_total+ '$earned' WHERE username ='$earnuser'")or die(mysql_error());
echo "<br/>";
echo "<br/>";
//echo ("UPDATE accounts SET acct_balance = acct_balance + '$earned',earned_total=earned_total+ '$earned' WHERE username ='{$ref_info['referral']}' LIMIT 1");
//as you can see i tried 2 different thing sbut nothing works if someone can help me or maybe a shorter way to rewrite it that would help to.
}


Thanks

Re: referral system help

Posted: Sun Aug 07, 2011 6:51 pm
by nite4000
Got it working.