How to export database to excel ? I have table like this :
+---------------------------------------------------------------------------------------+
id |title
----------------------------------------------------------------------------------------
 52 |   Book A  
 54 |   <div editor_id="mce_editor_0" align="justify">Pembayaran Dividen PT. Telkom Tbk. untuk Tahun Buku 2007 Tahap I akan dilaksanakan mulai tanggal  18 Desember 2007 dengan mempergunakan Surat Pemberitahuan Pembayaran Dividen (SPPD) sebagai bukti pembayaran.</div>
+---------------------------------------------------------------------------------------+
And I have script for export like this:
<?php
// nama file
$namaFile = "report.xls";
// Function penanda awal file (Begin Of File) Excel
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
// Function penanda akhir file (End Of File) Excel
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
// Function untuk menulis data (angka) ke cell excel
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
// Function untuk menulis data (text) ke cell excel
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
// header file excel
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,
    pre-check=0");
//header("Content-Type: application/force-download");
//header("Content-Type: application/octet-stream");
  header("Content-Type: application/x-msdownload");
  // header untuk nama file
  header("Content-Disposition: attachment;
    filename=".$namaFile."");
  //header("Content-Transfer-Encoding: binary ");
  // memanggil function penanda awal file excel
  xlsBOF();
 // ------ membuat kolom pada excel --- //
 // mengisi pada cell A1 (baris ke-0, kolom ke-0)
 xlsWriteLabel(0,0,"ID");               
 xlsWriteLabel(0,1,"TITLE");     
 // koneksi ke mysql
 mysql_connect("localhost", "root", "");
 mysql_select_db("db_lama");
 // query menampilkan semua data
 $query = "SELECT * FROM bf_articles ";
 $hasil = mysql_query($query);
 // nilai awal untuk baris cell
 $noBarisCell = 1;
 // nilai awal untuk nomor urut data
 $noData = 1;
 while ($data = mysql_fetch_array($hasil))
 {
   // menampilkan no. urut data
   xlsWriteNumber($noBarisCell,0,$data['id']);
   xlsWriteLabel($noBarisCell,1,$data['title']);
  // increment untuk no. baris cell dan no. urut data
  $noBarisCell++;
  $noData++;
 }
 // memanggil function penanda akhir file excel
 xlsEOF();
 exit();
 ?>
This is not working, there's an error
file error: data may have been lost
What can i do ? please help me :(