<?php
	//
	require_once $_SERVER['DOCUMENT_ROOT'] . '/db_connection.php';
// 	include("php/erster_name.inc.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 voxlatina WHERE ("  . $db_feld . " LIKE '%" . $suchwort . "%' OR " . $db_feld .  " LIKE '%«" . $suchwort . "%') AND (Textgattung = 'Epistula')  ORDER BY ". $db_feld . " ASC";
	$sql_result = $db->query($sql_select);
	//
	while ($row = $sql_result->fetch_object()) {
		if($db_feld == "Ort") {$d = $row->$db_feld;} else {$d = erster_name($row->$db_feld);}
		// jQuery-autocomplete verlangt "value-label"
		$data[] = array('value' => $d, 'label' => $d);
	}
	//
	echo json_encode($data);
	ob_flush();
	flush();
	//
?>
