<?php
include_once('details1.php');

  // output headers so that the file is downloaded rather than displayed

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=Topup_Report.xls');

// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');

// output the column headings
fputcsv($output, array('RequestID', 'Date', 'Airtime Sent', 'Recipient', 'Name', 'Group', 'Status',));

// fetch the data

$rows = mysql_query("SELECT airtime_sending_records.requestid,airtime_sending_records.date_sent, airtime_sending_records.airtime_sent, airtime_sending_records.recipient, airtime_contacts.fname, airtime_groups.name, airtime_sending_records.status FROM airtime_sending_records INNER JOIN airtime_contacts ON airtime_sending_records.recipient = airtime_contacts.contact INNER JOIN airtime_groups ON airtime_contacts.group_id = airtime_groups.group_id WHERE airtime_sending_records.customer_id = '$session_id' ORDER BY airtime_sending_records.date_sent DESC");

	//$rows = mysql_query("SELECT requestid, date_sent, airtime_sent, recipient, status FROM airtime_sending_records WHERE customer_id = '$session_id' ORDER BY date_sent DESC");
	
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row);

?>