<?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=Billing_Report.xls');

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

// output the column headings
fputcsv($output, array('TransID', 'TransTime', 'FirstName', 'MiddleName', 'LastName', 'MSISDN',));


// fetch the data
	$mpname = $_GET['mpesa_account_name'];
$rows = mysql_query("select * from api_topups where BillRefNumber = '$mpname'");

	//$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);

?>