forked from prodgrammer21/PHP-CRUD-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf.php
56 lines (46 loc) · 1.29 KB
/
pdf.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
52
53
54
55
56
<?php
require('./database.php');
require_once __DIR__ . '/vendor/autoload.php';
if (isset($_POST['exportToPdf'])) {
$currentDate = date("Y-m-d h:m:s");
$queryAccounts = "SELECT * FROM accounts";
$sqlAccounts = mysqli_query($connection, $queryAccounts);
$rowAccounts = "";
while ($rowAccount = mysqli_fetch_array($sqlAccounts)) {
$rowAccounts .= '
<tr>
<td>'.$rowAccount['id'].'</td>
<td>'.$rowAccount['username'].'</td>
<td>'.$rowAccount['password'].'</td>
</tr>
';
}
$html = '
<link rel="stylesheet" href="./pdf.css">
<h1> ACCOUNTS PDF by bossROD </h1>
<table>
<tr>
<td><strong>Name: </strong></td>
<td>bossROD </td>
</tr>
<tr>
<td><strong>Date Exported: </strong></td>
<td>'.$currentDate.' </td>
</tr>
</table>
<table class="accounts-table">
<tr>
<th>ID</th>
<th>USERNAME</th>
<th>PASSWORD</th>
</tr>
'.$rowAccounts.'
</table>
';
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML($html);
$mpdf->Output("PDF_$currentDate.pdf", "D");
} else {
echo '<script>window.location.href = "/php-crud-tutorial/index.php"</script>';
}
?>