2009-02-17 13:14:53 +00:00
|
|
|
<?php
|
|
|
|
$q = (!$_GET["q"])? "" : strtolower($_GET["q"]);
|
|
|
|
if (!$q) return;
|
|
|
|
//Connection mysql
|
2010-05-03 08:19:48 +00:00
|
|
|
$link = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) or
|
|
|
|
die("Impossible de se connecter : " . mysql_error());
|
2009-02-17 13:14:53 +00:00
|
|
|
$db_selected = mysql_select_db(MYSQL_DB, $link);
|
2010-02-10 17:27:03 +00:00
|
|
|
if (!$db_selected) { die ('Impossible de sélectionner la base de données : ' . mysql_error()); }
|
|
|
|
//Lecture des données mysql
|
|
|
|
$sql = "SET NAMES 'utf8'";
|
|
|
|
$result = mysql_query($sql);
|
2009-02-17 13:14:53 +00:00
|
|
|
$sql = "SELECT codNaf5, libNaf5 FROM tabnaf5 WHERE codNaf5 LIKE '%$q%' OR libNaf5 LIKE '%$q%' ORDER BY poids DESC";
|
|
|
|
$result = mysql_query($sql);
|
2010-05-03 08:19:48 +00:00
|
|
|
$output = array();
|
2009-02-17 13:14:53 +00:00
|
|
|
if ( mysql_num_rows($result)>0 && mysql_num_rows($result)!=FALSE ){
|
|
|
|
while ($row = mysql_fetch_assoc($result)) { $items[$row['codNaf5']] = "".$row['libNaf5'].""; }
|
2010-05-03 08:19:48 +00:00
|
|
|
//Envoi des informations
|
|
|
|
$separator = " , ";
|
2009-02-17 13:14:53 +00:00
|
|
|
foreach ($items as $key=>$value) {
|
|
|
|
if (strpos(strtolower($key), $q) !== false || strpos(strtolower($value), $q) !== false ) {
|
2010-05-03 08:19:48 +00:00
|
|
|
$output[] = array(
|
|
|
|
'label' => $key . $separator . $value,
|
|
|
|
'value' => $key
|
|
|
|
);
|
2009-02-17 13:14:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-03 08:19:48 +00:00
|
|
|
echo json_encode($output);
|
2009-02-17 13:14:53 +00:00
|
|
|
?>
|