<?php
require_once 'conexion.php';

$id = $_GET['id_arrendatario'] ?? 0;

$sql = "SELECT nombre, rut FROM acompanantes WHERE id_arrendatario = ?";

$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);
$stmt->execute();
$res = $stmt->get_result();

$data = [];

while ($row = $res->fetch_assoc()) {
    $data[] = $row;
}

echo json_encode($data);