-
Notifications
You must be signed in to change notification settings - Fork 1
/
viewEmp.php
72 lines (63 loc) · 1.9 KB
/
viewEmp.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
<?php
class Database {
private $conn;
public function __construct($servername, $username, $password, $database) {
$this->conn = new mysqli($servername, $username, $password, $database);
if ($this->conn->connect_error) {
die("Connection failed: " . $this->conn->connect_error);
}
}
public function getAllEmployees() {
$employees = [];
$sqlEmployees = "SELECT * FROM employee";
$resultEmployees = $this->conn->query($sqlEmployees);
if ($resultEmployees->num_rows > 0) {
while ($row = $resultEmployees->fetch_assoc()) {
$employees[] = $row;
}
}
return $employees;
}
public function closeConnection() {
$this->conn->close();
}
}
// Database connection parameters
$servername = "localhost";
$username = "root";
$password = "";
$database = "project_database";
$db = new Database($servername, $username, $password, $database);
$employees = $db->getAllEmployees();
$db->closeConnection();
?>
<table>
<thead>
<tr>
<th>Employee ID</th>
<th>Employee Name</th>
<th>Email ID</th>
<th>Address</th>
<th>Phone Number</th>
<th>Post</th>
<th>Date of Join</th>
<th>Basic</th>
</tr>
</thead>
<tbody>
<?php
foreach ($employees as $employee) {
echo "<tr>
<td>{$employee['emp_id']}</td>
<td>{$employee['emp_name']}</td>
<td>{$employee['email_id']}</td>
<td>{$employee['address']}</td>
<td>{$employee['phone_no']}</td>
<td>{$employee['post']}</td>
<td>{$employee['date_of_join']}</td>
<td>{$employee['basic']}</td>
</tr>";
}
?>
</tbody>
</table>