-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_dashboard.php
103 lines (87 loc) · 2.63 KB
/
user_dashboard.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['username'])) {
header("Location: index.php");
exit();
}
include 'config.php';
$username = $_SESSION['username'];
// Query the database to fetch user details based on the username
$sql = "SELECT * FROM users WHERE name = '$username'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// User found, fetch user details
$row = $result->fetch_assoc();
$name = $row['name'];
} else {
// User not found (This should not happen if user is logged in)
echo "Error: User not found.";
exit();
}
// Query the database to fetch points table
$sql_points = "SELECT team_name,
SUM(wins + losses + no_result) AS matches_played,
wins AS wins,
losses AS losses,
no_result AS no_result,
points AS points,
nrr AS nrr
FROM teams
GROUP BY team_name
ORDER BY points DESC, nrr DESC, wins DESC";
$result_points = $conn->query($sql_points);
$points_table = [];
if ($result_points->num_rows > 0) {
while ($row = $result_points->fetch_assoc()) {
$points_table[] = $row;
}
} else {
echo "No data found in teams.";
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
<link rel="icon" href="./media/scorecard.com.png" type="image/png">
<link rel="stylesheet" href="css/table.css">
</head>
<body>
<h2>Welcome to Dashboard, <?php echo $name; ?>.</h2>
<h3>Points Table</h3>
<table>
<tr>
<th>Position</th>
<th>Team</th>
<th>Matches Played</th>
<th>Wins</th>
<th>Losses</th>
<th>Tie/No Result</th>
<th>Points</th>
<th>NRR</th>
</tr>
<?php
$position = 1;
foreach ($points_table as $team) {
$row_class = $position <= 4 ? 'top-team' : '';
echo "<tr class='$row_class'>";
echo "<td>" . $position . "</td>";
echo "<td>" . $team['team_name'] . "</td>";
echo "<td>" . $team['matches_played'] . "</td>";
echo "<td>" . $team['wins'] . "</td>";
echo "<td>" . $team['losses'] . "</td>";
echo "<td>" . $team['no_result'] . "</td>";
echo "<td>" . $team['points'] . "</td>";
echo "<td>" . $team['nrr'] . "</td>";
echo "</tr>";
$position++;
}
?>
</table>
<p><a href="index.php">Logout</a></p>
</body>
</html>