30 lines
761 B
PHP
30 lines
761 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['email'], $term) !== false)
|
|
{
|
|
// Add the necessary "value" and "label" fields and append to result set
|
|
$stranka['value'] = $stranka['email'];
|
|
$stranka['label'] = "{$stranka['email']}";
|
|
$matches[] = $stranka;
|
|
}
|
|
}
|
|
|
|
// Truncate, encode and return the results
|
|
$matches = array_slice($matches, 0, 5);
|
|
print json_encode($matches);
|
|
|
|
?>
|