<?php
$Cliente = isset($_POST['key']) ? $_POST["key"]  : ""; 

include_once('db_config.php');
ini_set('max_execution_time', 120);

   if( strlen($Cliente) > 0 ) {

      $first = true;
      $sql = "select sql_no_cache id, nombre, direccion, cuit, contacto, tipo_iva, telefonos, mail, observa from empresas where nombre like '" . $Cliente . "%' order by empresa";
      $result = $conn->query($sql);
      if ($result->num_rows > 0) {
         echo "[";
         while( $row = $result->fetch_assoc() ) {
            if( $first == false ) echo ",";
            echo "{\"option\":\"" . $row["id"] . "\",\"nombre\":\"" . $row["nombre"] . "\" }";
            $first = false;
         }
         echo "]";
      }
      else echo "[]";
      mysqli_free_result( $result ); 
   }
   mysqli_close($conn);
?>

