View sourcecode

The following files exists in this folder. Click to view.

match_history.php

71 lines ASCII Windows (CRLF)
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
require "auth.php";
require 
"database.php";
requireLogin();

$ladderID $_GET["ladder_id"] ?? null;

if (!
$ladderID) {
    die(
"No ladder selected");
}

$stmt $conn->prepare(
    
"SELECT m.PlayedAt,
            p1.Username AS Player1,
            p2.Username AS Player2,
            w.Username AS Winner
     FROM Matches m
     JOIN Players p1 ON m.Player1ID = p1.PlayerID
     JOIN Players p2 ON m.Player2ID = p2.PlayerID
     JOIN Players w  ON m.WinnerID  = w.PlayerID
     WHERE m.LadderID = ?
     ORDER BY m.PlayedAt DESC"
);
$stmt->execute([$ladderID]);
$matches $stmt->fetchAll();
?>

<!DOCTYPE html>
<html>
<head>
    <title>Match History</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">

<h2>Match History</h2>

<?php if (!$matches): ?>
    <div class="alert alert-info">
        No matches found for this ladder.
    </div>
<?php else: ?>
<table class="table table-striped">
<thead>
<tr>
    <th>Date</th>
    <th>Player 1</th>
    <th>Player 2</th>
    <th>Winner</th>
</tr>
</thead>
<tbody>
<?php foreach ($matches as $m): ?>
<tr>
    <td><?= htmlspecialchars($m["PlayedAt"]) ?></td>
    <td><?= htmlspecialchars($m["Player1"]) ?></td>
    <td><?= htmlspecialchars($m["Player2"]) ?></td>
    <td><strong><?= htmlspecialchars($m["Winner"]) ?></strong></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>

<a href="javascript:history.back()" class="btn btn-secondary">Back</a>

</div>
</body>
</html>