<?php
include 'dbconnect.php'; // or whatever includes your DB

if (isset($_POST['project_ids']) && is_array($_POST['project_ids'])) {
    $projectIds = $_POST['project_ids'];

    // Sanitize and implode for SQL
    $ids = array_map('intval', $projectIds); 
    $idList = implode(',', $ids);

    // Adjust this query to your schema (you might need a relation table)
    $sql = mysqli_query($conn, "
        SELECT DISTINCT tu.id, tu.name 
        FROM tbl_invite_user tu
        JOIN tbl_lead_user_access_projects pum ON pum.tbl_lead_user_access_projects_user_id = tu.id
        WHERE pum.tbl_lead_user_access_projects_project_id IN ($idList) AND tu.flag = 0
    ");

    echo '<select class="form-control"  name="assigned_user" id="assigned_user" data-choices data-choices-sorting-false>
    <option value="">Select Assigned User</option>';
    while ($row = mysqli_fetch_array($sql)) {
        echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
    }
    echo'</select>';
}
?>
