Jump to content

[SOLVED] Exporting to Excel


joshblue

Recommended Posts

Hows this  ;D

 

<?php
define(db_host, “YOUR DATABASE HOST");
define(db_user, “USERNAME");
define(db_pass, “PASSWORD");
define(db_link, mysql_connect(db_host,db_user,db_pass));
define(db_name, “DB_NAME");
mysql_select_db(db_name);
$select = “SELECT * FROM TABLE_NAME";
$export = mysql_query($select);
$count = mysql_num_fields($export);
for ($i = 0; $i < $count; $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/octet-stream");
header("Content-Disposition: attachment; filename=spreadsheet.xls");
header("Pragma: no-cache");
header("Expires: 0″);
print “$headern$data";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.