<?php
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="report.csv"');
$data=array();
$data[]=array("customer name","Cheque no","issued date","amount","Bar Date");
$from_date=$_REQUEST['from_date'];
$to_date=$_REQUEST['to_date'];

require_once "config.php";
if($from_date==""){
   $sql="select * from pdc_details where status='pending'";
 
}else{
$sql="select * from pdc_details  where issued_date>='".$from_date."' and  issued_date<='".$to_date."' and status='pending' ";
//echo $sql;die();
}
$query=mysqli_query($con,$sql);
if($query==false){
    die(mysqli_error($con));
}
while($result=mysqli_fetch_array($query)){
   $data[]=array($result['customer_name'],$result['check_no'],$result['issued_date'],$result['amount'],$result['bar_date']);
    
}
$fp = fopen('php://output', 'wb');
foreach ( $data as $line ) {
   // $val = explode(",", $line);
    fputcsv($fp, $line);
}
fclose($fp);
?>