1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
<?php
$_clients = array(
/*
array("fd_name"=>"Hadock","fd_firstname"=>"Alain","fd_state"=>"10001"),
array("fd_name"=>"Hadock","fd_firstname"=>"Alain","fd_state"=>"10001"),
array("fd_name"=>"Hadock","fd_firstname"=>"Alain","fd_state"=>"10001"),
array("fd_name"=>"Hadock","fd_firstname"=>"Alain","fd_state"=>"10001"),
array("fd_name"=>"Hadock","fd_firstname"=>"Alain","fd_state"=>"10001"),
array("fd_name"=>"Hadock","fd_firstname"=>"Alain","fd_state"=>"10001"),
array("fd_name"=>"Hadock","fd_firstname"=>"Alain","fd_state"=>"10001"),
array("fd_name"=>"Hadock","fd_firstname"=>"Alain","fd_state"=>"10001"),
*/
);
$clients = array(
);
$root="../";
include($root.'sql/db_connect.php');
$sql_search = 'SELECT fd_name,fd_firstname,fd_state FROM tb_clients ORDER BY fd_name';
$query_search = mysql_query($sql_search)or die(mysql_error());
$nb_search = mysql_num_rows($query_search);
while($data_search=mysql_fetch_assoc($query_search)){
$clients[]=$data_search;
}
// Cleaning up the term
$q = trim(strtolower(strip_tags($_GET['term'])));
if (!$q) return;
// Rudimentary search
$matches = array();
foreach($clients as $client){
if(stripos($client['fd_name'], $q) !== false){
#if (strpos(strtolower($city['city']), $q) !== false) {
// Add the necessary "value" and "label" fields and append to result set
$client['value']=$client['fd_name'];
$client['label']="{$client['fd_name']} {$client['fd_firstname']}, {$client['fd_state']}";
$matches[] = $client;
}
#else{
#$matches[]= '';
#}
}
// Truncate, encode and return the results => LIMIT THE OUTPUT
#$matches = array_slice($matches, 0, 10);
print json_encode($matches);
?> |
Partager