table
This commit is contained in:
parent
776b6970f3
commit
cc18b68f29
1 changed files with 88 additions and 34 deletions
122
matchinfo.php
122
matchinfo.php
|
|
@ -1,38 +1,92 @@
|
||||||
<?php
|
<?php
|
||||||
// Check if a match ID is provided in the GET request
|
// Read the JSON file
|
||||||
if (isset($_GET['matchid'])) {
|
$jsonData = file_get_contents('data/player_matches.json');
|
||||||
$matchId = $_GET['matchid'];
|
$playersData = json_decode($jsonData, true);
|
||||||
$filename = "data/matches/" . $matchId . ".json";
|
|
||||||
|
|
||||||
// Check if the JSON file for the given match ID exists
|
// Combine matches from all players
|
||||||
if (file_exists($filename)) {
|
$allMatches = [];
|
||||||
// Read and decode the JSON file
|
foreach ($playersData as $player) {
|
||||||
$jsonData = json_decode(file_get_contents($filename), true);
|
foreach ($player['player_matches'] as $match) {
|
||||||
|
$match['playername'] = $player['playername']; // Add playername to each match for reference
|
||||||
// Start building the HTML table
|
$allMatches[] = $match;
|
||||||
echo "<table border='1'>";
|
|
||||||
echo "<tr><th>Player Name</th><th>Kills</th><th>Damage Dealt</th><th>Time Survived</th><th>Rank</th></tr>";
|
|
||||||
|
|
||||||
// Loop through the JSON data to extract player stats
|
|
||||||
|
|
||||||
foreach ($jsonData['included'] as $includedItem) {
|
|
||||||
if ($includedItem['type'] == "participant"){
|
|
||||||
$playerStats = $includedItem['attributes']['stats'];
|
|
||||||
echo "<tr>";
|
|
||||||
echo "<td>" . htmlspecialchars($playerStats['name']) . "</td>";
|
|
||||||
echo "<td>" . htmlspecialchars($playerStats['kills']) . "</td>";
|
|
||||||
echo "<td>" . htmlspecialchars($playerStats['damageDealt']) . "</td>";
|
|
||||||
echo "<td>" . htmlspecialchars($playerStats['timeSurvived']) . "</td>";
|
|
||||||
echo "<td>" . htmlspecialchars($playerStats['winPlace']) . "</td>";
|
|
||||||
echo "</tr>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "</table>";
|
|
||||||
} else {
|
|
||||||
echo "JSON file not found for the given match ID.";
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
echo "No match ID provided.";
|
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
// Sort matches by createdAt date
|
||||||
|
usort($allMatches, function ($a, $b) {
|
||||||
|
return strtotime($b['createdAt']) - strtotime($a['createdAt']);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get the last 5 matches
|
||||||
|
$lastMatches = array_slice($allMatches, 0, 8);
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<?php include './includes/head.php'; ?>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<?php include './includes/navigation.php'; ?>
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<img src="./images/banner2.png" alt="banner" class="banner">
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<section>
|
||||||
|
<h2>Latest Matches</h2>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<!-- <th>Match Date</th> -->
|
||||||
|
<tr><th>Player Name</th><th>Kills</th><th>Damage Dealt</th><th>Time Survived</th><th>Rank</th></tr>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
// Check if a match ID is provided in the GET request
|
||||||
|
if (isset($_GET['matchid'])) {
|
||||||
|
$matchId = $_GET['matchid'];
|
||||||
|
$filename = "data/matches/" . $matchId . ".json";
|
||||||
|
|
||||||
|
// Check if the JSON file for the given match ID exists
|
||||||
|
if (file_exists($filename)) {
|
||||||
|
// Read and decode the JSON file
|
||||||
|
$jsonData = json_decode(file_get_contents($filename), true);
|
||||||
|
|
||||||
|
foreach ($jsonData['included'] as $includedItem) {
|
||||||
|
if ($includedItem['type'] == "participant") {
|
||||||
|
$playerStats = $includedItem['attributes']['stats'];
|
||||||
|
echo "<tr>";
|
||||||
|
echo "<td>" . htmlspecialchars($playerStats['name']) . "</td>";
|
||||||
|
echo "<td>" . htmlspecialchars($playerStats['kills']) . "</td>";
|
||||||
|
echo "<td>" . htmlspecialchars($playerStats['damageDealt']) . "</td>";
|
||||||
|
echo "<td>" . htmlspecialchars($playerStats['timeSurvived']) . "</td>";
|
||||||
|
echo "<td>" . htmlspecialchars($playerStats['winPlace']) . "</td>";
|
||||||
|
echo "</tr>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "</table>";
|
||||||
|
} else {
|
||||||
|
echo "JSON file not found for the given match ID.";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "No match ID provided.";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
|
||||||
|
<?php include './includes/footer.php'; ?>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue