I have a MySQL database with information in it that I want exported to a CSV file.
This will work in Safari and FireFox, but not IE. Hep?
with query() being
This will work in Safari and FireFox, but not IE. Hep?
PHP:
<?php
session_start();
header("Cache-control: private"); // IE6 fix
include('../MyResources/include.php');
$WHD_DB = WHD_DB_CONNECT();
//Login checking that is not relevant to this Q
$csv_output = "Asset_Number,Checked_in_by,Date,Time,SID,First_Name,Last_Name,Status,Assessment(Commas removed),Ticket_number,Charger,ByIP,Edited";
$csv_output .= "\n";
$Query = query("select * from checkin",$WHD_DB);
while($row = mysql_fetch_array($Query)) {
//We need to get rid of commas because they screw up the CSV file.
//Assessment is the only place where commas could appear
$Assessment = str_replace(","," ",$row['Assessment']);
$csv_output .= "$row[Asset_Number],$row[Checked_in_by],$row[Date],$row[Time],$row[SID],$row[First_Name],$row[Last_Name],$row[Status],'$Assessment',$row[Ticket_number],$row[Charger],$row[ByIP],$row[Edited]";
$csv_output .= "\n";
}
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=" . date("Y-m-d") . "_Checkin_Dump.csv");
print $csv_output;
exit;
?>
with query() being
PHP:
function query($query,$db_cnx) {
$result = mysql_query ($query, $db_cnx);
if(!$result) {
//Email is set in the config file. If the admin does not want error reporting on, they set it to 1
if($Email == 0) {
$Message = "Something failed inside of the checkin program.\nInformation is as follows\nFailed with: '" . $query . "'\n" . mysql_error() . "\nWhen running " . $_SERVER['PHP_SELF'] . "\n From user: " . $_SESSION['name'];
mail("[email protected]", "Query failure", $Message);
echo "Email report sent to dev<br />";
} else {
}
echo "Error.. <br />MySQL said : <br /><textarea readonly='readonly' cols='120' rows='2'>" . mysql_error() . "</textarea>";
echo "<br />With query: <br /><textarea readonly='readonly' cols='120' rows='2'>" . $query . "</textarea>";
die();
} else {
}
return $result;
}