<?php
session_start();
include "connect.php";
$currentpage=100;
$activepage="HomePage";
if(!isset($_SESSION['admin_login'])){ header("location:index.php");}



?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>:: SCSCROWD  | Dashboard ::</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <?php include "common/CSS_link.php";?>
  <style>
  .doctor-schedule{max-height:254px}
.doctor-schedule .table-bordered{border:2px solid #e3e3e3;margin-bottom:0;background:#fff}
.table-bordered>tbody>tr>td,.table>thead>tr>th{border:2px solid #ddd;color:#777;font-size:14px;letter-spacing:.2px;font-weight:500;text-align:center;padding:7px}
.table>thead>tr>th{color:#0082c8;font-weight:600;font-family:'Lato',sans-serif;text-transform:uppercase;letter-spacing:2px}
.doctor-schedule h5{margin:0}
  </style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
  <header class="main-header">
    <?php include "common/header.php";?>
  </header>  
  <aside class="main-sidebar">    
    <section class="sidebar">
      <?php include "common/LEFT_sidebar.php";?>
  </aside>  
  <div class="content-wrapper">    
    <section class="content-header">
      <h1>
        Dashboard
        <small></small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Dashboard</li>
      </ol>
    </section>
 <section class="content">      
      <div class="row">
	  <?php
	  
							/*$no_date_query = "SELECT * FROM `no_date_tbl`";
$no_result_query = mysqli_query($conn,$no_date_query);
$date_list = array();
while($no_row = mysqli_fetch_assoc($no_result_query)){
	
	$day_no  = round((strtotime($no_row['to_date']) - strtotime($no_row['from_date']))/(60 * 60 * 24));

	for($i = 0; $i <= $day_no; $i++ ){
$date_list[] = date('Y-m-d',strtotime('+'.( $i ).' days',strtotime($no_row['from_date'])));
	}
	
}
				$view_company1 = "SELECT * FROM user_tbl ";  
				$rs_result_company1 = mysqli_query($conn,$view_company1);  
				while($row_company1 = mysqli_fetch_array($rs_result_company1)){
					$q_sql="SELECT * FROM `user_tbl` WHERE id = '".$row_company1['id']."'";
					$q_query=mysqli_query($conn,$q_sql." ORDER BY id DESC");
					$row=mysqli_fetch_array($q_query);
					$id=$row['id'];
					$user_unique_id = $row['user_unique_id'];
					$pay_date = $row['pay_date'];
					$rank = $row['rank'];
					date_default_timezone_set('Asia/Kolkata'); 
					$c_date = date('d-m-Y');
							
							
							if($rank == 1){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day  = round((strtotime($c_date) - strtotime($row['rank_date']))/(60 * 60 * 24)) + 1;
								if($day > 50){
									$day = 50;
								}
								$no_day = 0;
								if($day > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day++;
								}
								
								}
								
								}else if($day > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day++;
								}
								
								}
								
								}
								 $amt = ($day - $no_day)  * 5;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 2){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								
								$day2  = round((strtotime($c_date) - strtotime($row['rank_date2']))/(60 * 60 * 24)) + 1;
								if($day2 > 50){
									$day2 = 50;
								}
								
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								
								$amt = ($day1 - $no_day1)  * 5 + ($day2 - $no_day2) * 10;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 3){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($c_date) - strtotime($row['rank_date3']))/(60 * 60 * 24)) + 1;
								if($day3 > 50){
									$day3 = 50;
								}
								$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								
								$amt = ($day1 - $no_day1)  * 5 + ($day2 - $no_day2)  * 10 + ($day3 - $no_day3)  * 15;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 4){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								
									$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
									$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date4'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								$day4  = round((strtotime($c_date) - strtotime($row['rank_date4']))/(60 * 60 * 24)) + 1;
								if($day4 > 50){
									$day4 = 50;
								}
								$no_day4 = 0;
								if($day4 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date4']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}else if($day4 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								}
								
								$amt = ($day1 - $no_day1) * 5 + ($day2 - $no_day2) * 10 + ($day3 - $no_day3)  * 15 + ($day4 - $no_day4)  * 25;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 5){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date4'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$no_day4 = 0;
								if($day4 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date4']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}else if($day4 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date5'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}
								$day5  = round((strtotime($c_date) - strtotime($row['rank_date5']))/(60 * 60 * 24)) + 1;
								if($day5 > 50){
									$day5 = 50;
								}
								$no_day5 = 0;
								if($day5 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date5']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}else if($day5 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								}
								$amt = ($day1 - $no_day1) * 5 + ($day2 - $no_day2) * 10 + ($day3 - $no_day3)  * 15 + ($day4 - $no_day4 )  * 25 + ($day5 - $no_day5)  * 50;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 6){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date4'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$no_day4 = 0;
								if($day4 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date4']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}else if($day4 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date5'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$no_day5 = 0;
								if($day5 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date5']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}else if($day5 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date6'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}
								$day6  = round((strtotime($c_date) - strtotime($row['rank_date6']))/(60 * 60 * 24)) + 1;
								if($day6 > 50){
									$day6 = 50;
								}
								$no_day6 = 0;
								if($day6 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date6']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}else if($day6 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								}
								
								$amt = ($day1 - $no_day1) * 5 + ($day2 - $no_day2)  * 10 + ($day3 - $no_day3)  * 15 + ($day4 - $no_day4)  * 25 + ($day5 - $no_day5) * 50 + ($day6 - $no_day6)  * 75;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 7){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date4'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$no_day4 = 0;
								if($day4 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date4']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}else if($day4 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date5'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$no_day5 = 0;
								if($day5 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date5']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}else if($day5 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date6'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 50){
									$day6 = 50;
								}
									$no_day6 = 0;
								if($day6 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date6']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}else if($day6 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date7'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}
								$day7  = round((strtotime($c_date) - strtotime($row['rank_date7']))/(60 * 60 * 24)) + 1;
								if($day7 > 70){
									$day7 = 70;
								}
								$no_day7 = 0;
								if($day7 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date7']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}else if($day7 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								}
								$amt = ($day1 - $no_day1)  * 5 + ($day2 - $no_day2)  * 10 + ($day3 - $no_day3) * 15 + ($day4 - $no_day4) * 25 + ($day5 - $no_day5)  * 50 + ($day6 - $no_day6)  * 75 + ($day7 - $no_day7)  * 100;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 8){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date4'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$no_day4 = 0;
								if($day4 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date4']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}else if($day4 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date5'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$no_day5 = 0;
								if($day5 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date5']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}else if($day5 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date6'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 50){
									$day6 = 50;
								}
									$no_day6 = 0;
								if($day6 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date6']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}else if($day6 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date7'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 70){
									$day7 = 70;
								}
								$no_day7 = 0;
								if($day7 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date7']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}else if($day7 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date8'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}
								$day8  = round((strtotime($c_date) - strtotime($row['rank_date8']))/(60 * 60 * 24)) + 1;
								if($day8 > 70){
									$day8 = 70;
								}
								$no_day8 = 0;
								if($day8 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date8']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}else if($day8 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								}
								$amt = ($day1 - $no_day1)  * 5 + ($day2 - $no_day2)  * 10 + ($day3 - $no_day3)  * 15 + ($day4 - $no_day4)  * 25 + ($day5 - $no_day5)  * 50 + ($day6 - $no_day6) * 75 + ($day7 - $no_day7)  * 100 + ($day8 - $no_day8)  * 200;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 9){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date4'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$no_day4 = 0;
								if($day4 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date4']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}else if($day4 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date5'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$no_day5 = 0;
								if($day5 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date5']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}else if($day5 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date6'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 50){
									$day6 = 50;
								}
									$no_day6 = 0;
								if($day6 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date6']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}else if($day6 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date7'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 70){
									$day7 = 70;
								}
								$no_day7 = 0;
								if($day7 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date7']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}else if($day7 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date8'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 70){
									$day8 = 70;
								}
								$no_day8 = 0;
								if($day8 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date8']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}else if($day8 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date9'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}
								$day9  = round((strtotime($c_date) - strtotime($row['rank_date9']))/(60 * 60 * 24)) + 1;
								if($day9 > 70){
									$day9 = 70;
								}
								$no_day9 = 0;
								if($day9 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date9']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}else if($day9 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								}
								$amt = ($day1 - $no_day1)  * 5 + ($day2- $no_day2)  * 10 + ($day3 - $no_day3)  * 15 + ($day4 - $no_day4)  * 25 + ($day5 - $no_day5)  * 50 + ($day6 - $no_day6)  * 75 + ($day7 - $no_day7) * 100 + ($day8 - $no_day8)  * 200 + ($day9 - $no_day9)  * 300;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 10){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date4'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$no_day4 = 0;
								if($day4 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date4']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}else if($day4 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date5'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$no_day5 = 0;
								if($day5 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date5']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}else if($day5 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date6'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 50){
									$day6 = 50;
								}
									$no_day6 = 0;
								if($day6 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date6']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}else if($day6 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date7'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 70){
									$day7 = 70;
								}
								$no_day7 = 0;
								if($day7 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date7']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}else if($day7 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date8'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 70){
									$day8 = 70;
								}
								$no_day8 = 0;
								if($day8 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date8']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}else if($day8 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date9'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}
								$day9  = round((strtotime($row['rank_date10']) - strtotime($row['rank_date9']))/(60 * 60 * 24));
								if($day9 > 70){
									$day9 = 70;
								}
								$no_day9 = 0;
								if($day9 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date9']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}else if($day9 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date10'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}
								$day10  = round((strtotime($c_date) - strtotime($row['rank_date10']))/(60 * 60 * 24)) + 1;
								if($day10 > 100){
									$day10 = 100;
								}
								$no_day10 = 0;
								if($day10 > 100){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 100 days',strtotime($row['rank_date10']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date10']))){
								$no_day10++;
								}
								
								}
								
								}else if($day10 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date10']))){
								$no_day10++;
								}
								
								}
								}
								
								
								$amt = ($day1 - $no_day1)  * 5 + ($day2- $no_day2)  * 10 + ($day3 - $no_day3)  * 15 + ($day4 - $no_day4)  * 25 + ($day5 - $no_day5)  * 50 + ($day6 - $no_day6)  * 75 + ($day7 - $no_day7) * 100 + ($day8 - $no_day8)  * 200 + ($day9 - $no_day9)  * 300 + ($day10 - $no_day10)  * 500;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 11){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date4'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$no_day4 = 0;
								if($day4 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date4']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}else if($day4 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date5'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$no_day5 = 0;
								if($day5 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date5']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}else if($day5 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date6'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 50){
									$day6 = 50;
								}
									$no_day6 = 0;
								if($day6 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date6']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}else if($day6 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date7'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 70){
									$day7 = 70;
								}
								$no_day7 = 0;
								if($day7 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date7']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}else if($day7 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date8'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 70){
									$day8 = 70;
								}
								$no_day8 = 0;
								if($day8 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date8']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}else if($day8 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date9'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}
								$day9  = round((strtotime($row['rank_date10']) - strtotime($row['rank_date9']))/(60 * 60 * 24));
								if($day9 > 70){
									$day9 = 70;
								}
								$no_day9 = 0;
								if($day9 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date9']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}else if($day9 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date10'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}
								$day10  = round((strtotime($row['rank_date11']) - strtotime($row['rank_date10']))/(60 * 60 * 24));
								if($day10 > 100){
									$day10 = 100;
								}
								$no_day10 = 0;
								if($day10 > 100){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 100 days',strtotime($row['rank_date10']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date10']))){
								$no_day10++;
								}
								
								}
								
								}else if($day10 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date11'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date10']))){
								$no_day10++;
								}
								
								}
								
								}
								$day11  = round((strtotime($c_date) - strtotime($row['rank_date11']))/(60 * 60 * 24)) + 1;
								if($day11 > 100){
									$day11 = 100;
								}
								$no_day11 = 0;
								if($day11 > 100){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 100 days',strtotime($row['rank_date11']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date11']))){
								$no_day11++;
								}
								
								}
								
								}else if($day11 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date11']))){
								$no_day11++;
								}
								
								}
								}
								
								
				
								$amt = ($day1 - $no_day1)  * 5 + ($day2- $no_day2)  * 10 + ($day3 - $no_day3)  * 15 + ($day4 - $no_day4)  * 25 + ($day5 - $no_day5)  * 50 + ($day6 - $no_day6)  * 75 + ($day7 - $no_day7) * 100 + ($day8 - $no_day8)  * 200 + ($day9 - $no_day9)  * 300 + ($day10 - $no_day10)  * 500 + ($day11 - $no_day11)  * 750;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 12){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date4'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$no_day4 = 0;
								if($day4 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date4']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}else if($day4 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date5'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$no_day5 = 0;
								if($day5 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date5']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}else if($day5 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date6'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 50){
									$day6 = 50;
								}
									$no_day6 = 0;
								if($day6 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date6']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}else if($day6 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date7'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 70){
									$day7 = 70;
								}
								$no_day7 = 0;
								if($day7 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date7']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}else if($day7 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date8'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 70){
									$day8 = 70;
								}
								$no_day8 = 0;
								if($day8 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date8']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}else if($day8 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date9'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}
								$day9  = round((strtotime($row['rank_date10']) - strtotime($row['rank_date9']))/(60 * 60 * 24));
								if($day9 > 70){
									$day9 = 70;
								}
								$no_day9 = 0;
								if($day9 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date9']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}else if($day9 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date10'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}
								$day10  = round((strtotime($row['rank_date11']) - strtotime($row['rank_date10']))/(60 * 60 * 24));
								if($day10 > 100){
									$day10 = 100;
								}
								$no_day10 = 0;
								if($day10 > 100){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 100 days',strtotime($row['rank_date10']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date10']))){
								$no_day10++;
								}
								
								}
								
								}else if($day10 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date11'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date10']))){
								$no_day10++;
								}
								
								}
								
								}
								$day11  = round((strtotime($row['rank_date12']) - strtotime($row['rank_date11']))/(60 * 60 * 24));
								if($day11 > 100){
									$day11 = 100;
								}
								$no_day11 = 0;
								if($day11 > 100){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 100 days',strtotime($row['rank_date11']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date11']))){
								$no_day11++;
								}
								
								}
								
								}else if($day11 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date12'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date11']))){
								$no_day11++;
								}
								
								}
								
								}
								$day12  = round((strtotime($c_date) - strtotime($row['rank_date12']))/(60 * 60 * 24)) + 1;
								if($day12 > 150){
									$day12 = 150;
								}
								$no_day12 = 0;
								if($day12 > 150){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 150 days',strtotime($row['rank_date12']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date12']))){
								$no_day12++;
								}
								
								}
								
								}else if($day12 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date12']))){
								$no_day12++;
								}
								
								}
								}
								
								$amt = ($day1 - $no_day1)  * 5 + ($day2- $no_day2)  * 10 + ($day3 - $no_day3)  * 15 + ($day4 - $no_day4)  * 25 + ($day5 - $no_day5)  * 50 + ($day6 - $no_day6)  * 75 + ($day7 - $no_day7) * 100 + ($day8 - $no_day8)  * 200 + ($day9 - $no_day9)  * 300 + ($day10 - $no_day10)  * 500 + ($day11 - $no_day11)  * 750 + ($day12 - $no_day12)  * 1000;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 13){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date4'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$no_day4 = 0;
								if($day4 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date4']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}else if($day4 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date5'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$no_day5 = 0;
								if($day5 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date5']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}else if($day5 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date6'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 50){
									$day6 = 50;
								}
									$no_day6 = 0;
								if($day6 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date6']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}else if($day6 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date7'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 70){
									$day7 = 70;
								}
								$no_day7 = 0;
								if($day7 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date7']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}else if($day7 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date8'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 70){
									$day8 = 70;
								}
								$no_day8 = 0;
								if($day8 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date8']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}else if($day8 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date9'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}
								$day9  = round((strtotime($row['rank_date10']) - strtotime($row['rank_date9']))/(60 * 60 * 24));
								if($day9 > 70){
									$day9 = 70;
								}
								$no_day9 = 0;
								if($day9 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date9']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}else if($day9 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date10'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}
								$day10  = round((strtotime($row['rank_date11']) - strtotime($row['rank_date10']))/(60 * 60 * 24));
								if($day10 > 100){
									$day10 = 100;
								}
								$no_day10 = 0;
								if($day10 > 100){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 100 days',strtotime($row['rank_date10']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date10']))){
								$no_day10++;
								}
								
								}
								
								}else if($day10 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date11'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date10']))){
								$no_day10++;
								}
								
								}
								
								}
								$day11  = round((strtotime($row['rank_date12']) - strtotime($row['rank_date11']))/(60 * 60 * 24));
								if($day11 > 100){
									$day11 = 100;
								}
								$no_day11 = 0;
								if($day11 > 100){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 100 days',strtotime($row['rank_date11']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date11']))){
								$no_day11++;
								}
								
								}
								
								}else if($day11 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date12'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date11']))){
								$no_day11++;
								}
								
								}
								
								}
								$day12  = round((strtotime($row['rank_date13']) - strtotime($row['rank_date12']))/(60 * 60 * 24));
								if($day12 > 150){
									$day12 = 150;
								}
								$no_day12 = 0;
								if($day12 > 150){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 150 days',strtotime($row['rank_date12']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date12']))){
								$no_day12++;
								}
								
								}
								
								}else if($day12 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date13'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date12']))){
								$no_day12++;
								}
								
								}
								
								}
								$day13  = round((strtotime($c_date) - strtotime($row['rank_date13']))/(60 * 60 * 24)) + 1;
								if($day13 > 150){
									$day13 = 150;
								}
								$no_day13 = 0;
								if($day13 > 150){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 150 days',strtotime($row['rank_date13']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date13']))){
								$no_day13++;
								}
								
								}
								
								}else if($day13 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date13']))){
								$no_day13++;
								}
								
								}
								}
								
								$amt = ($day1 - $no_day1)  * 5 + ($day2- $no_day2)  * 10 + ($day3 - $no_day3)  * 15 + ($day4 - $no_day4)  * 25 + ($day5 - $no_day5)  * 50 + ($day6 - $no_day6)  * 75 + ($day7 - $no_day7) * 100 + ($day8 - $no_day8)  * 200 + ($day9 - $no_day9)  * 300 + ($day10 - $no_day10)  * 500 + ($day11 - $no_day11)  * 750 + ($day12 - $no_day12)  * 1000 + ($day13 - $no_day13)  * 1500;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 14){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date4'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$no_day4 = 0;
								if($day4 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date4']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}else if($day4 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date5'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$no_day5 = 0;
								if($day5 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date5']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}else if($day5 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date6'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 50){
									$day6 = 50;
								}
									$no_day6 = 0;
								if($day6 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date6']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}else if($day6 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date7'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 70){
									$day7 = 70;
								}
								$no_day7 = 0;
								if($day7 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date7']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}else if($day7 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date8'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 70){
									$day8 = 70;
								}
								$no_day8 = 0;
								if($day8 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date8']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}else if($day8 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date9'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}
								$day9  = round((strtotime($row['rank_date10']) - strtotime($row['rank_date9']))/(60 * 60 * 24));
								if($day9 > 70){
									$day9 = 70;
								}
								$no_day9 = 0;
								if($day9 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date9']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}else if($day9 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date10'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}
								$day10  = round((strtotime($row['rank_date11']) - strtotime($row['rank_date10']))/(60 * 60 * 24));
								if($day10 > 100){
									$day10 = 100;
								}
								$no_day10 = 0;
								if($day10 > 100){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 100 days',strtotime($row['rank_date10']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date10']))){
								$no_day10++;
								}
								
								}
								
								}else if($day10 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date11'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date10']))){
								$no_day10++;
								}
								
								}
								
								}
								$day11  = round((strtotime($row['rank_date12']) - strtotime($row['rank_date11']))/(60 * 60 * 24));
								if($day11 > 100){
									$day11 = 100;
								}
								$no_day11 = 0;
								if($day11 > 100){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 100 days',strtotime($row['rank_date11']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date11']))){
								$no_day11++;
								}
								
								}
								
								}else if($day11 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date12'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date11']))){
								$no_day11++;
								}
								
								}
								
								}
								$day12  = round((strtotime($row['rank_date13']) - strtotime($row['rank_date12']))/(60 * 60 * 24));
								if($day12 > 150){
									$day12 = 150;
								}
								$no_day12 = 0;
								if($day12 > 150){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 150 days',strtotime($row['rank_date12']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date12']))){
								$no_day12++;
								}
								
								}
								
								}else if($day12 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date13'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date12']))){
								$no_day12++;
								}
								
								}
								
								}
								$day13  = round((strtotime($row['rank_date14']) - strtotime($row['rank_date13']))/(60 * 60 * 24));
								if($day13 > 150){
									$day13 = 150;
								}
								$no_day13 = 0;
								if($day13 > 150){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 150 days',strtotime($row['rank_date13']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date13']))){
								$no_day13++;
								}
								
								}
								
								}else if($day13 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date14'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date13']))){
								$no_day13++;
								}
								
								}
								
								}
								$day14  = round((strtotime($c_date) - strtotime($row['rank_date14']))/(60 * 60 * 24)) + 1;
								if($day14 > 350){
									$day14 = 350;
								}
								$no_day14 = 0;
								if($day14 > 350){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 350 days',strtotime($row['rank_date14']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date14']))){
								$no_day14++;
								}
								
								}
								
								}else if($day14 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date14']))){
								$no_day14++;
								}
								
								}
								}
								$amt = ($day1 - $no_day1)  * 5 + ($day2- $no_day2)  * 10 + ($day3 - $no_day3)  * 15 + ($day4 - $no_day4)  * 25 + ($day5 - $no_day5)  * 50 + ($day6 - $no_day6)  * 75 + ($day7 - $no_day7) * 100 + ($day8 - $no_day8)  * 200 + ($day9 - $no_day9)  * 300 + ($day10 - $no_day10)  * 500 + ($day11 - $no_day11)  * 750 + ($day12 - $no_day12)  * 1000 + ($day13 - $no_day13)  * 1500 + ($day14 - $no_day14)  * 2500;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 15){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$no_day1 = 0;
								if($day1 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								$no_day1++;
								}
								
								}
								
								}else if($day1 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date2'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date']))){
								 $no_day1++;
								}
								
								}
								
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$no_day2 = 0;
								if($day2 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date2']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}else if($day2 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date3'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date2']))){
								$no_day2++;
								}
								
								}
								
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$no_day3 = 0;
								if($day3 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date3']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}else if($day3 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date4'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date3']))){
								$no_day3++;
								}
								
								}
								
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$no_day4 = 0;
								if($day4 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date4']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}else if($day4 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date5'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date4']))){
								$no_day4++;
								}
								
								}
								
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$no_day5 = 0;
								if($day5 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date5']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}else if($day5 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date6'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date5']))){
								$no_day5++;
								}
								
								}
								
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 50){
									$day6 = 50;
								}
									$no_day6 = 0;
								if($day6 > 50){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 50 days',strtotime($row['rank_date6']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}else if($day6 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date7'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date6']))){
								$no_day6++;
								}
								
								}
								
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 70){
									$day7 = 70;
								}
								$no_day7 = 0;
								if($day7 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date7']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}else if($day7 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date8'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date7']))){
								$no_day7++;
								}
								
								}
								
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 70){
									$day8 = 70;
								}
								$no_day8 = 0;
								if($day8 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date8']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}else if($day8 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date9'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date8']))){
								$no_day8++;
								}
								
								}
								
								}
								$day9  = round((strtotime($row['rank_date10']) - strtotime($row['rank_date9']))/(60 * 60 * 24));
								if($day9 > 70){
									$day9 = 70;
								}
								$no_day9 = 0;
								if($day9 > 70){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 70 days',strtotime($row['rank_date9']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}else if($day9 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date10'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date9']))){
								$no_day9++;
								}
								
								}
								
								}
								$day10  = round((strtotime($row['rank_date11']) - strtotime($row['rank_date10']))/(60 * 60 * 24));
								if($day10 > 100){
									$day10 = 100;
								}
								$no_day10 = 0;
								if($day10 > 100){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 100 days',strtotime($row['rank_date10']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date10']))){
								$no_day10++;
								}
								
								}
								
								}else if($day10 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date11'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date10']))){
								$no_day10++;
								}
								
								}
								
								}
								$day11  = round((strtotime($row['rank_date12']) - strtotime($row['rank_date11']))/(60 * 60 * 24));
								if($day11 > 100){
									$day11 = 100;
								}
								$no_day11 = 0;
								if($day11 > 100){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 100 days',strtotime($row['rank_date11']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date11']))){
								$no_day11++;
								}
								
								}
								
								}else if($day11 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date12'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date11']))){
								$no_day11++;
								}
								
								}
								
								}
								$day12  = round((strtotime($row['rank_date13']) - strtotime($row['rank_date12']))/(60 * 60 * 24));
								if($day12 > 150){
									$day12 = 150;
								}
								$no_day12 = 0;
								if($day12 > 150){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 150 days',strtotime($row['rank_date12']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date12']))){
								$no_day12++;
								}
								
								}
								
								}else if($day12 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date13'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date12']))){
								$no_day12++;
								}
								
								}
								
								}
								$day13  = round((strtotime($row['rank_date14']) - strtotime($row['rank_date13']))/(60 * 60 * 24));
								if($day13 > 150){
									$day13 = 150;
								}
								$no_day13 = 0;
								if($day13 > 150){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 150 days',strtotime($row['rank_date13']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date13']))){
								$no_day13++;
								}
								
								}
								
								}else if($day13 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date14'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date13']))){
								$no_day13++;
								}
								
								}
								
								}
								$day14  = round((strtotime($row['rank_date15']) - strtotime($row['rank_date14']))/(60 * 60 * 24));
								if($day14 > 350){
									$day14 = 350;
								}
								$no_day14 = 0;
								if($day14 > 350){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 350 days',strtotime($row['rank_date14']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date14']))){
								$no_day14++;
								}
								
								}
								
								}else if($day14 > 0){    
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] < date('Y-m-d',strtotime($row['rank_date15'])) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date14']))){
								$no_day14++;
								}
								
								}
								
								}
								$day15  = round((strtotime($c_date) - strtotime($row['rank_date15']))/(60 * 60 * 24)) + 1;
								if($day15 > 350){
									$day15 = 350;
								}
								$no_day15 = 0;
								if($day15 > 350){
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime('+ 350 days',strtotime($row['rank_date15']))) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date15']))){
								$no_day15++;
								}
								
								}
								
								}else if($day15 > 0){
									
								for($j = 0; $j < count($date_list); $j++){
								
								if($date_list[$j] <= date('Y-m-d',strtotime($c_date)) && $date_list[$j] >= date('Y-m-d',strtotime($row['rank_date15']))){
								$no_day15++;
								}
								
								}
								}
								
								$amt = ($day1 - $no_day1)  * 5 + ($day2- $no_day2)  * 10 + ($day3 - $no_day3)  * 15 + ($day4 - $no_day4)  * 25 + ($day5 - $no_day5)  * 50 + ($day6 - $no_day6)  * 75 + ($day7 - $no_day7) * 100 + ($day8 - $no_day8)  * 200 + ($day9 - $no_day9)  * 300 + ($day10 - $no_day10)  * 500 + ($day11 - $no_day11)  * 750 + ($day12 - $no_day12)  * 1000 + ($day13 - $no_day13)  * 1500 + ($day14 - $no_day14)  * 2500 + ($day15 - $no_day15)  * 4000;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}
				}					*/
		?>
		<div class="col-lg-6 col-xs-6">        
          <div class="small-box bg-red">
            <div class="inner">
			 <?php
				$view_company = "SELECT * FROM user_tbl WHERE id <> 1";  
				$rs_result_company = mysqli_query($conn,$view_company);  
				$row_company = mysqli_num_rows($rs_result_company);  
		?> 
              <h3><?php echo $row_company;?></h3>

              <p>Total Members</p>
            </div>
            <div class="icon">
              <i class="ion ion-person-add"></i>
            </div>
           </div>
        </div>
        <div class="col-lg-6 col-xs-6">        
          <div class="small-box bg-primary">
            <div class="inner">
              <h3><?php 
			  
			   
				$view_company = "SELECT * FROM user_tbl WHERE id <> 1 AND pay_status = 1";  
				$rs_result_company = mysqli_query($conn,$view_company);  
				$row_company = mysqli_num_rows($rs_result_company);  
	
				
				echo "0";
				
			  ?></h3>

              <p>Total Amount</p>
            </div>
            <div class="icon">
              <i class="fa fa-inr"></i>
            </div>
             </div>
        </div>  
      </div>
	  </section>
	  </div>
  <footer class="main-footer">
    <?php include "common/footer.php";?>
  </footer>  
</div>
<!-- ./wrapper -->

<?php include "common/JS_link.php";?>
</body>
</html>