-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
76 lines (65 loc) · 2.63 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php $users = require __DIR__ . "/api/getUsers.php"; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mysql PHP | CRUD</title>
<link rel="stylesheet" type="text/css" href="./css/tailwind.min.css" />
</head>
<body class="bg-gray-100">
<header class="bg-white h-16 shadow-sm px-8 flex items-center">
<h1 class="text-gray-700 text-lg font-semibold">CRUD App using MySQL and PHP</h1>
</header>
<main class="bg-white max-w-4xl rounded shadow my-8 sm:mx-8 lg:mx-auto px-4 py-8">
<a href="create.php" class="btn-primary mb-2">Add new user</a>
<!-- component -->
<section class="font-mono">
<div class="w-full overflow-hidden rounded-lg shadow-sm">
<div class="w-full overflow-x-auto">
<table class="w-full">
<thead>
<tr class="text-md font-semibold tracking-wide text-left text-gray-900 bg-gray-100 uppercase border-b border-gray-600">
<th class="px-4 py-3">Name</th>
<th class="px-4 py-3">Gender</th>
<th class="px-4 py-3">Age</th>
<th class="px-4 py-3"></th>
</tr>
</thead>
<tbody class="bg-white">
<?php foreach($users as $user) : ?>
<tr class="text-gray-700">
<td class="px-4 py-3 border">
<div class="flex items-center text-sm">
<div class="relative w-8 h-8 mr-3 rounded-full md:block">
<img class="object-cover w-full h-full rounded-full" src="<?= $user['image'] ?>" alt="" loading="lazy" />
<div class="absolute inset-0 rounded-full shadow-inner" aria-hidden="true"></div>
</div>
<div>
<p class="font-semibold text-black"><?= $user['fullname'] ?></p>
<a href="#" class="text-primary-400"><?= $user['email'] ?></a>
</div>
</div>
</td>
<td class="px-4 py-3 text-md font-semibold border"><?= $user['gender'] ?></td>
<td class="px-4 py-3 text-md border"><?= $user['age'] ?></td>
<td class="px-4 py-3 text-sm border whitespace-nowrap">
<a href="update.php?id=<?= $user['id'] ?>" class="btn-primary">Edit</a>
<button onclick="confirmDelete(<?= $user['id'] ?>)" class="btn-red">Delete</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</section>
</main>
<script>
function confirmDelete(id) {
if (confirm('Are you sure to delete this user?')) {
window.location.href = 'api/deleteUser.php?id=' + id;
}
}
</script>
</body>
</html>