<?php
	//
	require_once $_SERVER['DOCUMENT_ROOT'] . '/db_connection.php';
	include("php/namen.inc.php");
	//
	if (!isset($_GET["term"])) { exit; } // "term" ist von jQuery-autocomplete festgelegt!
	$suchwort = addslashes($_GET["term"]);
	$db_feld = ($_GET["db_feld"]);
	//
	$sql_select = "SELECT DISTINCT (" . $db_feld  .") FROM societaslatina WHERE ("  . $db_feld . " LIKE '%" . $suchwort . "%' OR " . $db_feld .  " LIKE '%«" . $suchwort . "%') ORDER BY ". $db_feld . " ASC";
	$sql_result = $db->query($sql_select);
	//
	while ($row = $sql_result->fetch_object()) {
		if($db_feld == "Autor") {$d = erster_name($row->$db_feld);} else {$d = $row->$db_feld;}
		// zu lange Ausgaben kürzen
		if (strlen($d) > 60) {
			$d = preg_replace("/[^ ]*$/", '', substr($d, 0, 60));
		}
		// jQuery-autocomplete verlangt "value-label-Paar"
		$data[] = array('value' => $d, 'label' => $d);
	}
	//
	echo json_encode($data);
	ob_flush();
	flush();
	//
?>
