last 5 matches total

This commit is contained in:
Thijs Stobbelaar 2023-10-04 08:45:45 +02:00
parent e3ee038477
commit 20115d3e09

View file

@ -3,10 +3,22 @@
$jsonData = file_get_contents('data/player_matches.json');
$playersData = json_decode($jsonData, true);
// Function to get the last 5 matches for a player
function getLastMatches($player) {
return array_slice($player['player_matches'], -5);
// Combine matches from all players
$allMatches = [];
foreach ($playersData as $player) {
foreach ($player['player_matches'] as $match) {
$match['playername'] = $player['playername']; // Add playername to each match for reference
$allMatches[] = $match;
}
}
// 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, 5);
?>
<!DOCTYPE html>
@ -27,8 +39,9 @@ function getLastMatches($player) {
<main>
<section>
<h2>Welcome to DTCH - PUBG Clan</h2>
<table border="1">
<table border="1">
<thead>
<tr>
<th>Match Date</th>
@ -44,28 +57,25 @@ function getLastMatches($player) {
</thead>
<tbody>
<?php
foreach($playersData as $player) {
$matches = getLastMatches($player);
foreach($matches as $match) {
?>
<tr>
<td><?php echo date("Y-m-d", strtotime($match['createdAt'])); ?></td>
<td><?php echo $player['playername']; ?></td>
<td><?php echo $match['gameMode']; ?></td>
<td><?php echo $match['matchType']; ?></td>
<td><?php echo $match['mapName']; ?></td>
<td><?php echo $match['stats']['kills']; ?></td>
<td><?php echo $match['stats']['damageDealt']; ?></td>
<td><?php echo gmdate("H:i:s", $match['stats']['timeSurvived']); ?></td>
<td><?php echo $match['stats']['winPlace']; ?></td>
</tr>
<?php
}
foreach($lastMatches as $match) {
?>
<tr>
<td><?php echo date("Y-m-d", strtotime($match['createdAt'])); ?></td>
<td><?php echo $match['playername']; ?></td>
<td><?php echo $match['gameMode']; ?></td>
<td><?php echo $match['matchType']; ?></td>
<td><?php echo $match['mapName']; ?></td>
<td><?php echo $match['stats']['kills']; ?></td>
<td><?php echo $match['stats']['damageDealt']; ?></td>
<td><?php echo gmdate("H:i:s", $match['stats']['timeSurvived']); ?></td>
<td><?php echo $match['stats']['winPlace']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<h2>Welcome to DTCH - PUBG Clan</h2>
<p>Join us on our Discord:</p>
<a href="https://discord.gg/wMXsB3ZmNA" target="_blank" rel="noopener noreferrer">
<img src="./media/discordlogo.png" alt="Discord Logo" class="discord-logo">