<?php
require_once('conecta.php');
mysqli_set_charset($conecta,"utf8");

$q = $_GET['q'] ?? '';
$q = mysqli_real_escape_string($conecta,$q);

$data = [];

if($q!=''){

$sql = "
SELECT idcliente, ruc_ci, denominacion
FROM cliente
WHERE ruc_ci LIKE '%$q%'
OR denominacion LIKE '%$q%'
LIMIT 15
";

$res = mysqli_query($conecta,$sql);

while($f=mysqli_fetch_assoc($res)){
$data[] = [
'id'=>$f['idcliente'],
'text'=>$f['ruc_ci'].' - '.$f['denominacion'],
'nom'=>$f['denominacion']
];
}
}

header('Content-Type: application/json');
echo json_encode($data);