<?php
include("../includes/db_connection.php");
include("../includes/auth.php");
include("partials/header.php");

$associate_id = intval($_GET['id']);

$sql = "
SELECT c.*
FROM clients c
WHERE c.associate_id = ?
ORDER BY c.id DESC
";

$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $associate_id);
$stmt->execute();
$result = $stmt->get_result();
?>

<div class="container py-4">
<div class="card shadow">

<div class="card-header bg-dark text-white">
Associate Clients List
</div>

<div class="card-body">

<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead class="table-light">
<tr>
<th>ID</th>
<th>Client Name</th>
<th>Address</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>

<tbody>
<?php while($row=$result->fetch_assoc()): ?>
<tr>
<td><?= $row['id'] ?></td>
<td><?= $row['name'] ?></td>
<td><?= $row['address'] ?><br/><?= $row['city'] ?>, <?= $row['country'] ?></td>
<td><?= $row['email'] ?></td>
<td><?= $row['phone'] ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>

<a href="associates.php" class="btn btn-secondary mt-3">Back</a>

</div>
</div>
</div>

<?php include("partials/footer.php"); ?>