<?php include('../include/functions.php');
header("Content-Type: text/plain; charset=iso-8859-1");

$searchquery = dbEscapeString($_REQUEST['q']);
$limit = dbEscapeString($_REQUEST['limit']);
if ($limit == '') {
  $limit = 10;
}
if ($searchquery == '' || ! preg_match('/[0-9]+/', $searchquery) || ! preg_match('/[0-9]+/', $limit)) {
  exit;
}

$query = "SELECT distinct(stadt) FROM plz WHERE plz LIKE '$searchquery%' ORDER BY plz ASC LIMIT 0,$limit";
$result = dbQuery($query) or error('autocomplete_versnummer.php: Cannot read users');
while ($row = dbFetchRow($result)) {
  $stadt = $row['stadt'];
  print $stadt;
}
dbFreeResult($result);
