show last matches on front page

This commit is contained in:
Lanta 2023-10-04 08:43:16 +02:00
parent a51ce6397f
commit 11cb24f711

View file

@ -1,3 +1,14 @@
<?php
// Read the JSON file
$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);
}
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -16,6 +27,44 @@
<main> <main>
<section> <section>
<table border="1">
<thead>
<tr>
<th>Match Date</th>
<th>Player Name</th>
<th>Game Mode</th>
<th>MatchType</th>
<th>Map</th>
<th>Kills</th>
<th>Damage Dealt</th>
<th>Time Survived</th>
<th>Win Place</th>
</tr>
</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
}
}
?>
</tbody>
</table>
<h2>Welcome to DTCH - PUBG Clan</h2> <h2>Welcome to DTCH - PUBG Clan</h2>
<p>Join us on our Discord:</p> <p>Join us on our Discord:</p>
<a href="https://discord.gg/wMXsB3ZmNA" target="_blank" rel="noopener noreferrer"> <a href="https://discord.gg/wMXsB3ZmNA" target="_blank" rel="noopener noreferrer">