-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_excel.php
51 lines (50 loc) · 1.25 KB
/
export_excel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
include 'connect.php';
//mysql_select_db($database); //connect to database
session_start();
if(isset($_SESSION['cart'])){
$array_id_barang = array_column($_SESSION['cart'], 'idbarang');
}
$output = '';
if(isset($_POST["export_excel"])) {
$dtbarang = mysqli_query($conn, "select * from barang");
if(mysqli_num_rows($dtbarang) > 0) {
$output .= '
<table class="table" bordered="1">
<tr>
<th>id barang</th>
<th>nama barang</th>
<th>keterangan</th>
<th>harga</th>
<th>foto</th>
<th>quantity</th>
</tr>
';
while($data=mysqli_fetch_assoc($dtbarang)) {
$quantity = 0;
if(isset($_SESSION['cart'])){
foreach ($_SESSION["cart"] as $barang){
$id = $barang['idbarang'];
if($id==$data["idbarang"]) {
$quantity = $barang["quantity"];
}
}
}
$output .= '
<tr>
<td>'.$data["idbarang"].'</td>
<td>'.$data["namabarang"].'</td>
<td>'.$data["keterangan"].'</td>
<td>'.$data["harga"].'</td>
<td>'.$data["foto"].'</td>
<td>'.$quantity.'</td>
</tr>
';
}
$output .= '</table>';
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=download.xls");
echo $output;
}
}
?>