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
| $array = array();
/* si la requête est bien en Ajax et la méthode en GET ... */
if((strtolower(filter_input(INPUT_SERVER, 'HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest') && ($_SERVER['REQUEST_METHOD'] == 'GET')){
/* on récupère le terme et on le duplique en terme en transformant les espaces en tirets et tirets en espaces (au cas ou) */
$commune = str_replace("''","'",urldecode(htmlspecialchars($_REQUEST['name'])));
$query=$db->prepare('SELECT ts.id_service_public, ts.nom_service_public, ts.commune, ts.code_postal, ts.adresse
FROM table_temporaire_service ts
WHERE LOWER(ts.commune) LIKE LOWER(:commune) collate utf8_bin
ORDER BY ts.commune desc');
$query->setFetchMode(PDO::FETCH_OBJ);
$query->execute([':commune'=>'%'.$commune.'%']);
/* remplissage du tableau avec les termes récupéré en requete (ou non) */
while($q = $query->fetch()){
$array["communes"][] = [
'id' => $q->id_service,
'label' => $q->commune,
'value' => $q->commune,
'code_postal'=> $q->code_postal
];
}
if(isset($_GET['nomVille'])and isset($_GET['code_postal'])){
$req=$db->prepare("select id_budget,valeur_budget,annee_budget
from table_temporaire2_budget
where lower(nom_commune)=lower(:commune)
and year(CURDATE())=annee_budget
and code_postal=:code_postal");
$req->execute([':commune'=>$_GET['nomVille'],':code_postal'=>$_GET['code_postal'] ]);
if($req->rowCount()>0){
while($budget=$req->fetch(PDO::FETCH_OBJ)){$array['budget'][]=$budget;}
} |
Partager