last 5 matches total
This commit is contained in:
parent
11cb24f711
commit
c06b6c6091
1 changed files with 32 additions and 22 deletions
28
index.php
28
index.php
|
|
@ -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,6 +39,7 @@ function getLastMatches($player) {
|
|||
|
||||
<main>
|
||||
<section>
|
||||
<h2>Welcome to DTCH - PUBG Clan</h2>
|
||||
|
||||
<table border="1">
|
||||
<thead>
|
||||
|
|
@ -44,13 +57,11 @@ function getLastMatches($player) {
|
|||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach($playersData as $player) {
|
||||
$matches = getLastMatches($player);
|
||||
foreach($matches as $match) {
|
||||
foreach($lastMatches as $match) {
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo date("Y-m-d", strtotime($match['createdAt'])); ?></td>
|
||||
<td><?php echo $player['playername']; ?></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>
|
||||
|
|
@ -61,11 +72,10 @@ function getLastMatches($player) {
|
|||
</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">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue