<?php



// require('library/php-excel-reader/excel_reader2.php');

// require('library/SpreadsheetReader.php');

require('dbconfig.php');

$con = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$con) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}


 

$filename = "datamasteritem.xls"; // File Name
// Download file
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
$user_query = mysqli_query($con,'select kode_cabang,kode,nama,harga,harga_beli from tbl_barang');

$flag = false;
while ($row = mysqli_fetch_assoc($user_query)) {
    if (!$flag) {
        // display field/column names as first row
        echo implode("\t", array_keys($row)) . "\r\n";
        $flag = true;
    }
    echo implode("\t", array_values($row)) . "\r\n";
}
?>

 