-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_matches.php
90 lines (77 loc) · 3.53 KB
/
view_matches.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tournament History</title>
<link rel="icon" href="./media/scorecard.com.png" type="image/png">
<link rel="stylesheet" href="css/view_matches.css">
</head>
<body>
<h2>Tournament History</h2>
<?php
// Include the configuration file
include 'config.php';
// Query to retrieve all data from tournament_data table
$sql = "SELECT * FROM tournament_data ORDER BY date DESC"; // Order by match_no in descending order
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Output table header
echo "<table>";
echo "<tr><th>Match No.</th><th>Date</th><th>Home</th><th>Away</th><th>Venue</th><th>Toss</th><th>Decision</th><th>Result</th><th>Actions</th></tr>";
// Output data of each row
$row_number = $result->num_rows; // Set initial row number to the number of rows in the result set
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row_number . "</td>"; // Display the row number
$formatted_date = date("F j, Y", strtotime($row['date']));
echo "<td>" . $formatted_date . "</td>";
echo "<td>" . $row['home_team'] . "</td>";
echo "<td>" . $row['away_team'] . "</td>";
echo "<td>" . $row['venue'] . "</td>";
echo "<td>" . $row['toss'] . "</td>";
echo "<td>" . $row['decision'] . "</td>";
echo "<td>" . $row['result'] . "</td>";
echo "<td class='action-buttons'>";
// Enable update button regardless of result value
echo "<button class='update-btn' data-match-no='" . $row['match_no'] . "' data-result='" . $row['result'] . "'>Update</button>";
echo "<button class='delete-btn' onclick='deleteMatch(" . $row['match_no'] . ")'>Delete</button>";
echo "</td>";
echo "</tr>";
$row_number--;
}
echo "</table>";
} else {
echo '<div style="text-align: center; font-size: 25px;">No data found.</div>';
}
?>
<p><a href="create_match.php">Insert Match Data</a></p>
<p><a href="admin_dashboard.php">Dashboard</a></p>
<p><a href="index.php">Logout</a></p>
<script>
function updateMatch(matchNo, result) {
// Check if result is not empty
if (result !== "") {
// Redirect to edit_match.php if result is not empty
window.location.href = "edit_match.php?match_no=" + matchNo;
} else {
// Redirect to update_match.php if result is empty
window.location.href = "update_match.php?match_no=" + matchNo;
}
}
function deleteMatch(matchNo) {
// Display a confirmation dialog
if (confirm('Are you sure you want to delete this match?')) {
// If user confirms, redirect to delete page with the match number
window.location.href = "delete_match.php?match_no=" + matchNo;
}
}
// Add event listener to update buttons for extra caution, in case gets clicked through some external script or browser quirk
document.querySelectorAll('.update-btn').forEach(button => {
button.addEventListener('click', function(event) {
updateMatch(button.getAttribute('data-match-no'), button.getAttribute('data-result'));
});
});
</script>
</body>
</html>