Get custom details from order in magento1

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once('app/Mage.php');
umask(0);
Mage::app('admin');
set_time_limit(1000000);
$time = time();
date_default_timezone_set('Asia/Calcutta');
$date = Mage::getModel('core/date')->gmtDate();
//Mage::getModel('core/date')->date('Y-m-d');
$from = date('Y-m-d ', strtotime($date . ' -1 days'));
$firstDate = date('Y-m-d H:i:s', strtotime($from . '00:00:00') - 19800);
$lastDate = date('Y-m-d H:i:s', strtotime($from . '23:59:59') - 19800);
error_reporting(E_ALL);
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$query= "SELECT sales_flat_order.increment_id,sales_flat_order.customer_firstname,sales_flat_order.customer_lastname,sales_flat_order.created_at,sales_flat_order.grand_total,sales_flat_order.customer_email,sales_flat_order.status
,sales_flat_order_payment.method FROM sales_flat_order
INNER JOIN sales_flat_order_payment
ON sales_flat_order.entity_id = sales_flat_order_payment.parent_id
WHERE created_at BETWEEN '2018-03-01' AND '2019-06-21'";
   // $query = 'select * from sales_flat_order LIMIT 10';
$results = $readConnection->fetchAll($query);
    /* get the results */
$output = fopen("php://output",'w') or die("Can't open php://output");
header("Content-Type:application/csv"); 
header("Content-Disposition:attachment;filename=orderdata.csv"); 
fputcsv($output, array('Order Id','Customer Firstname','Customer Lastname','Date','Order Value','Payment Method','Email','Status'));
foreach($results as $val) {
    fputcsv($output, $val);
}
fclose($output) or die("Can't close php://output");
  ?>

Comments