<?php include("../Header/Session.php"); ?>
<?php include("../Header/Connection.php"); ?>

<!DOCTYPE html>
<html lang="en">
<?php include ("../Header/head.php"); ?>
<body class="skin-default fixed-layout">

<!-- Main wrapper - style you can find in pages.scss -->
<div id="main-wrapper">    
<?php include ("../Header/header.php"); ?>
<?php include ("../Header/left_menu.php"); ?>
<?php include ("../Header/right_sidebar.php"); ?>
        
<!-- Page wrapper  -->
<div class="page-wrapper">
<!-- Container fluid  -->
<div class="container-fluid">
<!-- Bread crumb and right sidebar toggle -->
<!--?php include ("../Header/breadcumb.php"); ?-->
<br><br>
<!-- End Bread crumb and right sidebar toggle -->
    
    
                
    
<!-- Start Page Content -->
<!-- ============================================================== -->
<div class="row">
<div class="col-12">
    <div class="card">
        <div class="card-body">
            <h4 class="card-title">My Direct Ref Member</h4>
            <h6 class="card-subtitle">Export data to Copy, CSV, Excel, PDF & Print</h6>
            <div class="table-responsive m-t-40">
                <form method="post" action="../Controller/Database_sql.php" enctype="multipart/form-data">
                <table id="example23"
                    class="display nowrap table table-hover table-striped table-bordered"
                    cellspacing="0" width="100%">
                    <thead>
                        <tr>
                            <th>Referral ID</th>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Phone Number</th>
                            <th>Registered On</th>
                            <th>Number of Downline</th>
                            <!--th>Action</th--> 
                        </tr>
                    </thead>                                      
                    <tbody>
                        <?php
                        $q = "SELECT * 
						    FROM user
                            Where sponsor_code = '$ref_code'
                            And level ='2'
                            And status != '9'
                            And ref_code Like 'MGP%'
						    order by id Desc";
                        $result = $mysqli->query($q);
                        if ($result->num_rows > 0)
                        {
                        while($record = $result -> fetch_assoc())
                        {   
						    $id = $record['id'];
                            $ref_code = $record['ref_code'];
                            $sponsor_code = $record['sponsor_code'];
                            $type_of_user = $record['type_of_user'];
                            $rank = $record['rank'];
						    $name = $record['name'];
						    $email = $record['email'];
						    $password = $record['password'];
						    $phone_number = $record['phone_number'];
                            $created_date = date('d-m-Y h:i:s a ', strtotime($record['created_date']));  
                          
                            $sql_data = "SELECT COUNT(id) As num 
                            FROM user 
                            WHERE sponsor_code='$ref_code'
                            AND status='1'";
                            $result_data = $mysqli->query($sql_data);
	                        if ($result_data->num_rows > 0)
	                        {
		                        $row_data = $result_data ->fetch_assoc();
		                        $num_downline = $row_data['num'];
	                        }
                        ?>
                        <tr>
                            <td><?php echo $ref_code;?></td>
                            <td><?php echo $name;?></td>
                            <td><?php echo $email;?></td>
                            <td><?php echo $phone_number;?></td> 
                            <td><?php echo $created_date;?></td>
                            <td><?php echo $num_downline;?></td> 
                        </tr>
                        <?php
                        }
                        }
                        ?>
                    </tbody>
                </table>
                </form>
            </div>
        </div>
    </div>                      
</div>
</div>
<!-- ============================================================== -->
<!-- End PAge Content -->

</div>
<!-- End Container fluid  -->
</div>
<!-- End Page wrapper  -->

<!-- Footer Start-->
<?php include ("../Footer/footer.php"); ?>
<!-- Footer End-->

</div>
<!-- End Wrapper -->
<!-- All Jquery -->
    

<!-- All Jquery Start-->
<?php include ("../Header/all_jquery.php"); ?>
<!-- All Jquery End-->

    

</body>

</html>