<?php
include 'db.php';

// Create the database object
$db = new Database();

// SQL query to join swbf_players and swbf_stats
$query = "SELECT 
            swbf_players.player_last_name AS player_name,
            swbf_stats.stat_points,
            swbf_stats.stat_kills,
            swbf_stats.stat_deaths,
            swbf_stats.player_id
          FROM swbf_stats
          JOIN swbf_players ON swbf_players.id = swbf_stats.player_id";

// Execute the query
$result = $db->query($query);

// Fetch the data
$stats_data = [];
while ($row = $result->fetchArray()) {
    $stats_data[] = $row;
}

// Return the data as a JSON response
echo json_encode(['stats' => $stats_data]);
?>
