<?php
    require_once 'common/database.php';
        if(!isset($_SESSION['logged_in'])){
            header('location: index.php');
        }
    $output = '';
?>

<?php
    if(isset($_POST["export"])){
        $query = "SELECT * FROM tiket";

        $result = mysqli_query($db,$query);

        if(mysqli_num_rows($result) > 0){
            $output .= '
            <table style="width:90%;margin-top:25px;" border="2">
            <tr style="color:black;">
                <th><strong>No Tiket</strong></th>
                <th><strong>ID Pembeli</strong></th>
                <th><strong>Kode Paket</strong></th>
                <th><strong>No Kursi</strong></th>
            </tr>
            ';
            while($row = mysqli_fetch_array($result)){
                $output .='
                         <tr style="color:black;">
                                <td>'.$row["id_tiket"].'</td>
                                <td>'.$row["id_akun"].'</td>
                                <td>'.$row["kode_paket"].'</td>
                                <td>'.$row["no_kursi"].'</td>
                 
                            </tr>
                ';
            }
            $output .= '</table>';
            header('Content-Type: application/xls');
            header('Content-Disposition: attachment; filename=download2.xls');
            echo $output;
        }
    }
?>