"" && $_GET["ed"] <> ""){ $sd = substr(mysql_real_escape_string($_GET["sd"]),0,240); $ed = substr(mysql_real_escape_string($_GET["ed"]),0,240); $csv_output = "spend date,spend what,spend cat, spend value"; $csv_output .= "\n"; //$query = "select spend_nice_date, spend_what, spend_tag, spend_value from spending where spend_nice_date between \"".$sd."\" and \"".$ed."\" and spend_active = 1 and uid = ".$uid; $query = "select spend_nice_date, spend_what, cat_name as spend_tag, spend_value from spending, tbl_categories where spend_nice_date between \"".$sd."\" and \"".$ed."\" and spend_tag_id = tbl_categories.id and spend_active = 1 and spending.uid = ".$uid; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $csv_output .= "{$row['spend_nice_date']},{$row['spend_what']},{$row['spend_tag']},{$row['spend_value']}\n"; } header("Content-type: application/vnd.ms-excel"); //header("Content-disposition: csv" . date("Y-m-d") . ".xls"); header("Content-disposition: attachment; filename=" .date("Y-m-d").".csv"); print $csv_output; exit; } else { header("Location:../main.php"); } ?>