I have data in a MySQL database. I am sending the user a URL to get their data out as a excel file.
How can I, when they click the link, have a pop-up to download a excel with the record from MySQL?
I have all the information to get the record already. I just don't see how to have PHP create the excel file and let them download a file
include("con.php");
// Qry to fetch all records against date
$dateonedayback=strtotime('-1 day',strtotime(date("Y/m/d")));
$one_day=date("Y-m-d",$dateonedayback);
$qry_user_points = "SELECT u.points,u.db_add_date,u.user_email_id FROM tbl_user AS u WHERE u.points != '0' AND date(u.db_add_date)='".$one_day."' ";
$query_result= $con->db_query($qry_user_points);
header('Content-Type: application/vnd.ms-excel'); //define header info for browser
header('Content-Disposition: attachment; filename=Users-Points-Report-'.date('Ymd').'.xls');
$excel_header = array("Email","Points","Date");
for ($i = 0; $i < count($excel_header); $i++)
{
echo $excel_header[$i]."\t";
}
print("\n");
$j=0;
while($rowValue = $con->db_fetch_array($query_result))
{
$points = $rowValue['points'];
$emailID = $rowValue['user_email_id'];
$addedDate = $rowValue['db_add_date'];
// create an array to insert in excel with url encoding
$final_array = array(urlencode($points),urlencode($emailID),urlencode($addedDate));
$result_count =$con->db_num_rows($query_result);
$output = '';
for($k=0; $k < $con->db_num_rows($query_result); $k++)
{
if(!isset($final_array[$k]))
$output .= "NULL\t";
else
$output .= "$final_array[$k]\t";
}
$output = preg_replace("/\r\n|\n\r|\n|\r/", ' ', $output);
print(trim($output))."\t\n";
$j++;
} // while close
When i hit link it creates excel file but data not coming properly
it writes only points in excel file not email & date
please help me on this.