<?php include('../include/functions.php');

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

$query = "SELECT distinct(plz) 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)) {
  $plz = $row['plz'];
  print $plz . "\n";
}
dbFreeResult($result);
