To clean it up, I put this question with a new topic.
I'm using the autocompleter of "http://www.devbridge.com/sourcery/components/jquery-autocomplete/" but in a previous version because of its lightweight and speed. the version I used can be found here: https://code.google.com/p/jquery-autocomplete/source/browse/
Within that I try to receive results with
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
$(function() {
$("#ac1").autocomplete('search.php', {
selectFirst: true
});
$("#flush").click(function() {
var ac = $("#ac1").data('autocompleter');
if (ac && $.isFunction(ac.cacheFlush)) {
ac.cacheFlush();
} else {
alert('Error flushing cache');
}
});
the data.php is simply structured:
$data = array(
"Berlin" => "10178",
"Hamburg" => "20038",
"München" => "80331",
and the search.php file contains the following:
<?php
include 'data.php';
function autocomplete_format($results) {
foreach ($results as $result) {
echo $result[0] . '|' . $result[1] . "
";
}
}
if (isset($_GET['q'])) {
$q = strtolower($_GET['q']);
if ($q) {
foreach ($data as $key => $value) {
if (strpos(strtolower($key), $q) !== false) {
$results[] = array($key, $value);
}
}
}
}
$output = 'autocomplete';
if (isset($_GET['output'])) {
$output = strtolower($_GET['output']);
}
if ($output === 'json') {
echo json_encode($results);
} else {
echo autocomplete_format($results);
}
Now I try, that after I chose the right city from the dropdown menu there will be the number right beside the city (in the data.php) in an new label.
Try this:
echo $data['Berlin'];