<?php
	session_start();
	if($_SESSION['rid'])
	{
		$userid=$_SESSION['rid'];
	}
	else
	{
		header('location:../login.php');
	}
?>
<?php
include'connection.php';
$date=$_POST['date'];
$output = '';
if(isset($_POST["export"]))
{
 $query = "SELECT * FROM recharge where Userid='$userid' and Rechargedate='$date'";
 $result = mysqli_query($con, $query);
 if(mysqli_num_rows($result) > 0)
 {
  $output .= '<table class="table" Borders="All Borders" cellpadding="10">  
                    <tr>  
                        <th>Date</th>  
                        <th>Time</th> 
                        <th>Recharge Id</th>  
                        <th>Mobile No.</th>  
                        <th>Operator</th>  
                        <th>Amount</th>  
                        <th>Credit Used</th>  
                        <th>Status</th>
                        <th>Operator Id</th>
                    </tr>';
  while($row = mysqli_fetch_array($result))
  {
   $output .= ' <tr>  
                    <td>'.$row["Rechargedate"].'</td>  
                    <td>'.$row["Time"].'</td>
                    <td>'.$row["Id"].'</td>  
                    <td>'.$row["Mobile"].'</td>  
                    <td>'.$row["Companyname"].'</td>  
                    <td>'.$row["Amount"].'</td>
                    <td>'.$row["Debitamount"].'</td>
                    <td>'.$row["Status"].'</td>
                    <td>'.$row["Operatorid"].'</td>
                </tr>';
  }
  $output .= '</table>';
  header('Content-Type: application/xls');
  header('Content-Disposition: attachment; filename=download.xls');
  echo $output;
 }
 else
 {
     echo "<h2 style='color:red;'>Data Not Found !</h2>";
 }
}
?>
