I am trying to create a comma seperated value (CSV) file based on a mysql query. I want a user to click on a link, then they would be presented with the pop-up open document / save as dialog box.
I have tried a few approaches but have not had any success.
Any help or direction would be appreciated
Here is one of the things I have tried...this only displays the result in the browser window.
<?
$filename = "test";
$ext = "txt"; // file extension
$mime_type = (PMA_USR_BROWSER_AGENT == 'IE' || PMA_USR_BROWSER_AGENT == 'OPERA')
? 'application/octetstream'
: 'application/octet-stream';
header('Content-Type: ' . $mime_type);
header('Content-Disposition: inline; filename="' . $filename . '.' . $ext . '"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
print "Success";
?>
<?php
$hostname_hr_jobs = "10.1.0.65";
$database_hr_jobs = "hr_jobs";
$username_hr_jobs = "user";
$password_hr_jobs = "password";
$hr_jobs = mysql_pconnect($hostname_hr_jobs, $username_hr_jobs, $password_hr_jobs) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_hr_jobs, $hr_jobs);
$query_export_file = "SELECT * FROM job_postings";
$export_file = mysql_query($query_export_file, $hr_jobs) or die(mysql_error());
$row_export_file = mysql_fetch_assoc($export_file);
$totalRows_export_file = mysql_num_rows($export_file);
print "<b>"."job_title"."</b><br>";
do {
print $row_export_file['job_title']."\n";
} while ($row_export_file = mysql_fetch_assoc($export_file));
?>