-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.php
More file actions
71 lines (67 loc) · 1.74 KB
/
view.php
File metadata and controls
71 lines (67 loc) · 1.74 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
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
<?php
// Database connection settings
$servername = "localhost";
$username = "root";
$password = "140712";
$database = "users"; // or "sample_db" if that's what you used
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Fetch data from the users table
$sql = "SELECT category_id, name, email, age FROM users";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>View Users</title>
<style>
table {
width: 70%;
border-collapse: collapse;
margin: 20px auto;
}
th, td {
border: 1px solid #333;
padding: 10px;
text-align: center;
}
th {
background-color: #eee;
}
h2 {
text-align: center;
}
</style>
</head>
<body>
<h2>Registered Users</h2>
<table>
<tr>
<th>CATEGORY_ID</th>
<th>Name</th>
<th>Email</th>
<th>Age</th>
</tr>
<?php
if ($result->num_rows > 0) {
// Output each row
while($row = $result->fetch_assoc()) {
echo "<tr>
<td>" . $row["category_id"] . "</td>
<td>" . $row["name"] . "</td>
<td>" . $row["email"] . "</td>
<td>" . $row["age"] . "</td>
</tr>";
}
} else{
echo "<tr><td colspan='4'>No data found</td></tr>";
}
$conn->close();
?>
</table>
</body>
</html>