2020-08-14 13:36:36 +02:00

30 lines
799 B
PHP

<?php
include('../db.php');
$stranke = array();
$sqlpr = mysql_query("SELECT email, telefon, predmet, kraj, instruktor, ime_stranke FROM stranke");
while($rowpr = mysql_fetch_array($sqlpr))
array_push($stranke, $rowpr);
// Cleaning up the term
$term = trim(strip_tags(trim($_GET['term'])));
// Rudimentary search
$matches = array();
foreach($stranke as $stranka)
{
if(stripos($stranka['ime_stranke'], $term) !== false)
{
// Add the necessary "value" and "label" fields and append to result set
$stranka['value'] = $stranka['ime_stranke'];
$stranka['label'] = "{$stranka['ime_stranke']},{$stranka['email']}";
$matches[] = $stranka;
}
}
// Truncate, encode and return the results
$matches = array_slice($matches, 0, 5);
print json_encode($matches);
?>