<?php
// Include the connection.php file for database connection
include('connection.php');

if (isset($_GET['court_id'])) {
    $court_id = $_GET['court_id'];

    // Make sure to validate and sanitize $court_id to prevent SQL injection

    // Your database query
    $query = "SELECT total_pendency, total_disposal, total_institution FROM statistic_courts WHERE court_id = '$court_id'";

    // Execute the query and fetch data
    $result = mysqli_query($connection, $query);

    if ($result) {
        $data = mysqli_fetch_assoc($result);

        // Return the data as JSON to be used in the chart
        echo json_encode($data);
    } else {
        // Handle database query errors
        echo json_encode(['error' => 'Database query error']);
    }
} else {
    echo json_encode(['error' => 'Invalid court_id parameter']);
}
?>
