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

require_once "config.php";
if($from_date==""){
   $sql="select * from production_details where status='pending'";
 
}else{
$sql="select * from production_details  where order_date>='".$from_date."' and  order_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['order_date'],$result['due_date']);
    
}
$fp = fopen('php://output', 'wb');
foreach ( $data as $line ) {
   // $val = explode(",", $line);
    fputcsv($fp, $line);
}
fclose($fp);
?>