<?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "pattern")
    $pattern = $paramValue;
}

$dal = new DAL();
$sql = "SELECT id, " .
       "CASE WHEN " .
         "(LENGTH(surname) < 10 && LENGTH(firstname) < 10) " . 
           "THEN CONCAT(surname,', ',firstname) " . 
           "ELSE CONCAT(surname,', ',SUBSTRING(first_name,1,1)) " . 
       "END AS hint " .
       "FROM contact " .
       "WHERE surname LIKE '%$pattern%' OR first_name LIKE '%$pattern%'" ;
$result = $dal->query($sql);

echo json_encode ($result);


