<?php
include 'db.php'; 

    $search = $_GET['searchTerm2'];
    $cluster2 = $_GET['cluster2'];
    $json = [];
    
     if ($cluster2 ==='PRINCIPAL'){
   $sql = "SELECT  `idINMUEBLE`,  `INMUEBLE` FROM  `direcciones` WHERE  `INMUEBLE` LIKE '%".$search."%'"; 
        $result = $conn->query($sql);
        while($row = $result->fetch_assoc()){
            $json[] = ['id'=>$row['idINMUEBLE'], 'text'=>$row['INMUEBLE']];
        }
 }
 else{
      $sql = "SELECT  `idINMUEBLE`,  `INMUEBLE` FROM  `direcciones` WHERE  `cluster`='$cluster2' AND `INMUEBLE` LIKE '%".$search."%'"; 
        $result = $conn->query($sql);
        while($row = $result->fetch_assoc()){
            $json[] = ['id'=>$row['idINMUEBLE'], 'text'=>$row['INMUEBLE']];
        }
 }
echo json_encode($json);
 ?>