<?php
include('../config/dbcon.php');


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

    $query = "SELECT projectID, projectName FROM projects WHERE clientID = $clientID ORDER BY projectName";
    $result = mysqli_query($conn, $query);

    if ($result) {
        $projects = [];
        while ($row = mysqli_fetch_assoc($result)) {
            $projects[] = $row;
        }
        echo json_encode(['success' => true, 'projects' => $projects]);
    } else {
        echo json_encode(['success' => false, 'message' => 'Query failed: ' . mysqli_error($conn)]);
    }
} else {
    echo json_encode(['success' => false, 'message' => 'No client ID provided']);
}
?>
