<?php

$Cuenta = isset($_POST['key']) ? $_POST["key"]  : ""; 

//      $sql = "select sql_no_cache cuenta, denominacion from cuentas where cuenta like '" . $Cuenta . "%' and borrado=0 order by cuenta";
//      echo $sql . "<br/>";
//      echo $Cuenta . "<br/>";

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

   if( strlen($Cuenta) > 0 ) {

      $first = true;
      $sql = "select sql_no_cache cuenta, denominacion from cuentas where cuenta like '" . $Cuenta . "%' and borrado=0 order by cuenta";
//      echo $sql . "<br/>";
      $result = $conn->query($sql);
      if ($result->num_rows > 0) {
         echo "[";
         while( $row = $result->fetch_assoc() ) {
            if( $first == false ) echo ",";
            echo "{\"option\":\"" . $row["cuenta"] . "\",\"denominacion\":\"" . $row["denominacion"] . "\" }";
            $first = false;
         }
         echo "]";
      }
      else echo "[]";
      mysqli_free_result( $result ); 
   }
   mysqli_close($conn);
?>

