%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/bbw/farmaci/kritik-portale/public/
Upload File :
Create Path :
Current File : /var/www/html/bbw/farmaci/kritik-portale/public/autocomplete.php

<?php
chdir(dirname(__DIR__));

$db = include 'connect-views-db.php';
try {    
    $dbh = new PDO(
        $db['dsn'],
        $db['username'], 
        $db['password'], 
        array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
    );
} catch (Exception $ex) {
    echo json_encode(array());
    exit;
}

$searchString = isset($_GET['q']) ? $_GET['q'] : '';

$sql = "SELECT name, plz, loc_id, typ FROM "
    . "geosearch WHERE "
    . "plz LIKE :plz "
    . "OR name LIKE :name "
    //. "GROUP BY name "
    . "LIMIT 10";

$name = $searchString . '%';
$plz = '%' . $searchString . '%';

$stmt = $dbh->prepare($sql);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':plz', $plz);
$stmt->execute();

$typeaheadResults = [];
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $result) {
    $typeaheadResults[] = [
        'entry'     => $result['name'], 
        'plz'       => $result['plz'], 
        'loc_id'    => $result['loc_id'],
        'loc_typ'   => $result['typ']
    ];
}

echo json_encode($typeaheadResults);

Zerion Mini Shell 1.0