Trying to export data from db to excel
Posted: Tue Mar 07, 2006 10:39 am
Hi !!
Well I've been trying to export some data from a db but it keeps appering the following warning:
Warning: Cannot add header information - headers already sent by
My program is:
Hoping someone could help me!! 
Well I've been trying to export some data from a db but it keeps appering the following warning:
Warning: Cannot add header information - headers already sent by
My program is:
Code: Select all
@$link_id = mysql_connect("XXX", "XXX", "XXX") or die("Connection Failed");
$select_db = mysql_select_db("bd_amigokit",$link_id) or die("Connection Failed");
$select = "SELECT marca_modelo, promocion, tiempo_incluido, precio, costo_dolares, tipo_cambio, gain_loss, precio_iva, descuento_dist,
costo_equipod, subsidio_ctotal, porcentaje_subsidio, margen_inversion, observaciones, fecha, circular FROM akLib_GSM WHERE estatus='Liberada-00' ORDER BY marca_modelo";
$export = mysql_query($select);
$fields = mysql_num_fields($export);
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . "t";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "t";
}
$line .= $value;
}
$data .= trim($line)."n";
}
$data = str_replace("r","",$data);
if ($data == "") {
$data = "n(0) Records Found!n";
}
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$headern$data";