<?
function Referral_amount($userid,$amount) 
	{
$default_ref="select * from ref_levels";
$default_ref_result=mysql_query($default_ref);
if(mysql_num_rows($default_ref_result)>0)
	    {
		$lev=1;
		while($default_ref_row=mysql_fetch_array($default_ref_result)) 
{
$ref_ammount[$lev]=$default_ref_row['ref_levels'];
$lev++;
}}
$ref_date=date('Y-m-d');

	    $select_referral_query="select * from member_details where user_id=$userid";
		$select_referral_result=mysql_query($select_referral_query);
		if(mysql_num_rows($select_referral_result)>0)
	    {
  $select_referral_row=mysql_fetch_array($select_referral_result);
  $introid1 = $select_referral_row['intro_id'];
  $ref_total = $amount*$ref_ammount[1]/100;
  $ref_total = round($ref_total,0);
if($introid1!=0){
$insert_query=mysql_query("update member_details set bid_num=bid_num+$ref_total where user_id=$introid1");	
}
$select_referral_query="select * from member_details where user_id=$introid1";
		$select_referral_result=mysql_query($select_referral_query);
		if(mysql_num_rows($select_referral_result)>0)
	    {
  $select_referral_row=mysql_fetch_array($select_referral_result);
  $introid2 = $select_referral_row['intro_id'];
  $ref_total = $amount*$ref_ammount[2]/100;
  $ref_total = round($ref_total,0);
if($introid2!=0){
$insert_query=mysql_query("update member_details set bid_num=bid_num+$ref_total where user_id=$introid2");
}
$select_referral_query="select * from member_details where user_id=$introid2";
		$select_referral_result=mysql_query($select_referral_query);
		if(mysql_num_rows($select_referral_result)>0)
	    {
  $select_referral_row=mysql_fetch_array($select_referral_result);
  $introid3 = $select_referral_row['intro_id'];
  $ref_total = $amount*$ref_ammount[3]/100;
  $ref_total = round($ref_total,0);
if($introid3!=0){
$insert_query=mysql_query("update member_details set bid_num=bid_num+$ref_total where user_id=$introid3");
}
$select_referral_query="select * from member_details where user_id=$introid3";
		$select_referral_result=mysql_query($select_referral_query);
		if(mysql_num_rows($select_referral_result)>0)
	    {
  $select_referral_row=mysql_fetch_array($select_referral_result);
  $introid4 = $select_referral_row['intro_id'];
  $ref_total = $amount*$ref_ammount[4]/100;
  $ref_total = round($ref_total,0);
if($introid4!=0){
$insert_query=mysql_query("update member_details set bid_num=bid_num+$ref_total where user_id=$introid4");
}}}}}
}
















function Referral_Registration($userid) 
	{
$default_ref="select * from ref_levels";
$default_ref_result=mysql_query($default_ref);
if(mysql_num_rows($default_ref_result)>0)
	    {
		$lev=1;
		while($default_ref_row=mysql_fetch_array($default_ref_result)) 
{
$ref_ammount[$lev]=$default_ref_row['reg_bid'];
$lev++;
}}
$ref_date=date('Y-m-d');

	    $select_referral_query="select * from member_details where user_id=$userid";
		$select_referral_result=mysql_query($select_referral_query);
		if(mysql_num_rows($select_referral_result)>0)
	    {
  $select_referral_row=mysql_fetch_array($select_referral_result);
  $introid1 = $select_referral_row['intro_id'];
  $ref_total = $ref_ammount[1];
if($introid1!=0){
$insert_query=mysql_query("update member_details set bid_num=bid_num+$ref_total where user_id=$introid1");	
}
$select_referral_query="select * from member_details where user_id=$introid1";
		$select_referral_result=mysql_query($select_referral_query);
		if(mysql_num_rows($select_referral_result)>0)
	    {
  $select_referral_row=mysql_fetch_array($select_referral_result);
  $introid2 = $select_referral_row['intro_id'];
  $ref_total = $ref_ammount[2];
if($introid2!=0){
$insert_query=mysql_query("update member_details set bid_num=bid_num+$ref_total where user_id=$introid2");
}
$select_referral_query="select * from member_details where user_id=$introid2";
		$select_referral_result=mysql_query($select_referral_query);
		if(mysql_num_rows($select_referral_result)>0)
	    {
  $select_referral_row=mysql_fetch_array($select_referral_result);
  $introid3 = $select_referral_row['intro_id'];
  $ref_total = $ref_ammount[3];
if($introid3!=0){
$insert_query=mysql_query("update member_details set bid_num=bid_num+$ref_total where user_id=$introid3");
}
$select_referral_query="select * from member_details where user_id=$introid3";
		$select_referral_result=mysql_query($select_referral_query);
		if(mysql_num_rows($select_referral_result)>0)
	    {
  $select_referral_row=mysql_fetch_array($select_referral_result);
  $introid4 = $select_referral_row['intro_id'];
  $ref_total = $ref_ammount[4];
if($introid4!=0){
$insert_query=mysql_query("update member_details set bid_num=bid_num+$ref_total where user_id=$introid4");
}}}}}
}









?>