-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_users_excel.php
More file actions
40 lines (35 loc) · 1.01 KB
/
export_users_excel.php
File metadata and controls
40 lines (35 loc) · 1.01 KB
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
<?php
require_once 'connect/Connection.php';
// Set headers to force download as an Excel file
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=users_report.xls");
header("Pragma: no-cache");
header("Expires: 0");
// Create a new database connection
$database = new Connection();
$pdo = $database->getConnection();
// Fetch users from database
$query = "SELECT id, name, email, role, status FROM users";
$stmt = $pdo->prepare($query);
$stmt->execute();
$usersData = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Output table format for Excel
echo "<table border='1'>";
echo "<tr>
<th>User ID</th>
<th>Name</th>
<th>Email</th>
<th>Role</th>
<th>Status</th>
</tr>";
foreach ($usersData as $user) {
echo "<tr>
<td>{$user['id']}</td>
<td>{$user['name']}</td>
<td>{$user['email']}</td>
<td>{$user['role']}</td>
<td>{$user['status']}</td>
</tr>";
}
echo "</table>";
?>