Greetings,
I am having trouble with the following script, it keeps giving me these bogus messages. What should i do to get rid of these?
Here are the messages Below:
Connected Successfully
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/PMS/csv_export.php:4) in /var/www/html/PMS/csv_export.php on line 65
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/PMS/csv_export.php:4) in /var/www/html/PMS/csv_export.php on line 68
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/PMS/csv_export.php:4) in /var/www/html/PMS/csv_export.php on line 69
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/PMS/csv_export.php:4) in /var/www/html/PMS/csv_export.php on line 70
utctime error lowalarm highalarm point_1 point_2 point_3 point_4 point_5 point_6 point_7 point_8 point_9 point_10 point_11 point_12 point_13 point_14 point_15 point_16 point_17 point_18 point_19 point_20 point_21 point_22 point_23 point_24 point_25 point_26 point_27 point_28 point_29 point_30 point_31 point_32 point_33 point_34 point_35 point_36 point_37 point_38 point_39 point_40 point_41 point_42 no matching records found
Here is my Script Below:
<?php
pg_connect("host=172.18.74.10 port=5432 dbname=acquisuite_db user=pgadmin password=pgadmin")
or die ( 'Unable to connect to server.' );
printf("Connected Successfully");
$MM_param1panels = ''%'';
if (isset($HTTP_GET_VARS['panel'])) {
$MM_param1panels = $HTTP_GET_VARS['panel'];
}
$MM_param2panels = ''%'';
if (isset($HTTP_GET_VARS['startdate'])) {
$MM_param2panels = $HTTP_GET_VARS['startdate'];
}
$MM_param3panels = ''%'';
if (isset($HTTP_GET_VARS['enddate'])) {
$MM_param3panels = $HTTP_GET_VARS['enddate'];
}
$MM_param4panels = ''%'';
if (isset($HTTP_GET_VARS['order'])) {
$MM_param4panels = $HTTP_GET_VARS['order'];
}
$query = sprintf("SELECT * FROM %s WHERE utctime AT TIME ZONE 'MST' BETWEEN '%s' AND '%s' ORDER BY utctime %s", $MM_param1panels,$MM_param2panels,$MM_param3panels,$MM_param4panels);
$result = pg_exec($query);
$count = pg_num_fields($result);
for ($i = 0; $i < $count; $i++){
$header .= pg_fieldname($result,$i)."\t";
}
$result_count = 0;
while($result_count < $rowcount) {
$row = pg_fetch_row($result, $result_count);
// while($row = pg_fetch_row($result,$result_count++)){
set_time_limit(2); //2 second time limit within loop
$line = '';
foreach($row as $value){
if(!isset($value) || $value == ""){
$value = "\t";
}else{
important to escape any quotes to preserve them in the data.
$value = str_replace('"', '""', $value);
needed to encapsulate data in quotes because some data might be multi line.
the good news is that numbers remain numbers in Excel even though quoted.
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
set_time_limit(5); //20 minute time limit
this line is needed because returns embedded in the data have "\r"
and this looks like a "box character" in Excel
$data = str_replace("\r", "", $data);
Nice to let someone know that the search came up empty.
Otherwise only the column name headers will be output to Excel.
if ($data == "") {
$data = "\nno matching records found\n";
}
This line will stream the file to the user rather than spray it across the screen
header("Content-type: application/octet-stream");
replace excelfile.xls with whatever you want the filename to default to
header("Content-Disposition: attachment; filename=excelfile.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $header."\n".$data;
?>
I would appreciate it if someone could look at this. Maybe my script is wrong
Thanks,
Cameron