beberapa kode dibawah ini yang harus sesuai :
- user dan password mysql
- nama database
- query sql
<?php
$conn = new mysqli('localhost', 'root', 'password_kamu');
mysqli_select_db($conn, 'nama_database');
$sql = "
SELECT
ID, Nama, Kota, Tgl_Register, Email, Gender
FROM mst_member ORDER BY createdtm DESC";
$sqlQuery = mysqli_query($conn, $sql) or die(mysqli_error($conn));
$namaKolom = "";
$namaKolom = "ID" . "\t" .
"Nama" . "\t" .
"Kota" . "\t" .
"Tgl Register" . "\t" .
"Email" . "\t" .
"Gender" . "\t";
$setData = "";
while ($rec = mysqli_fetch_row($sqlQuery))
{
$rowData = "";
foreach ($rec as $value)
{
$value = '"' . $value . '"' . "\t";
$rowData .= $value;
}
$setData .= trim($rowData) . "\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=member_".date('Ymd').".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo ucwords($namaKolom) . "\n" . $setData . "\n";?>
- user dan password mysql
- nama database
- query sql
<?php
$conn = new mysqli('localhost', 'root', 'password_kamu');
mysqli_select_db($conn, 'nama_database');
$sql = "
SELECT
ID, Nama, Kota, Tgl_Register, Email, Gender
FROM mst_member ORDER BY createdtm DESC";
$sqlQuery = mysqli_query($conn, $sql) or die(mysqli_error($conn));
$namaKolom = "";
$namaKolom = "ID" . "\t" .
"Nama" . "\t" .
"Kota" . "\t" .
"Tgl Register" . "\t" .
"Email" . "\t" .
"Gender" . "\t";
$setData = "";
while ($rec = mysqli_fetch_row($sqlQuery))
{
$rowData = "";
foreach ($rec as $value)
{
$value = '"' . $value . '"' . "\t";
$rowData .= $value;
}
$setData .= trim($rowData) . "\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=member_".date('Ymd').".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo ucwords($namaKolom) . "\n" . $setData . "\n";?>
0 comments:
Post a Comment