0

ok so i have this code for a table.

$idUser = $_SESSION['id'];
$query = "SELECT b.*, c.name FROM bookings b JOIN user c ON b.userId=c.userId WHERE b.date >=CURDATE() and isdelete=0";
$result = mysqli_query($link, $query);
if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        echo '<tr>';
        echo '<td>' . $row['id'] . '</a></td>';
        echo '<td>' . $row['date'] . '</td>';
        echo '<td>' . $row['start'] . '</td>';
        echo '<td>' . $row['name'] . '</td>';
        if($row['isPayed']==0){
          echo '<td>Blom Lunas</td>';
        }
        else{
          echo '<td>Sudah Lunas</td>';
        }
        echo '</tr>';
    }
} else {
    echo '<tr><td colspan="6">No data in table</td></tr>';
}
echo '</table>';

how can i import this table into excel when i click a button bellow the table.

1
  • thx @RST good find Commented Nov 27, 2016 at 15:18

1 Answer 1

0

Best option is exporting selected data to csv file, not drawing table. Something like that:

$filename = 'data.csv';
while ($row = mysqli_fetch_assoc($result)) {
    $array_od_data = [
        $row['id'],
        $row['date'],
        $row['start'],
        $row['name'],
        $row['isPayed'] == 0 ? 'Blom Lunas' : 'Sudah Lunas'
    ];
    $line = implode(',', $array_od_data) . '\r\n';
    file_put_contents($filenae, $line, FILE_APPEND);
}

Then simply import data.csv file into Excel sheet

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.