<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
	
		<title>Los Angeles Stadt der Engel</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel='stylesheet' media='all' type="text/css" href="stylesheet.css" />
		<style type="text/css"></style>

	</head>
	
	<body>

		<?php
			require_once("db_connection.php");
			require_once("ml.txt");
		?>
			
		<div class='data' style='overflow: scroll;'>
		<B><p class="menue">Suchen einer Station mittels Anfangsbuchstaben</p><br /></B>

		<?php 
		
			if (empty($_GET['letters'])== FALSE) {
				$query = "SELECT stops.name AS Haltestellen,
							GROUP_CONCAT(DISTINCT routes.id 
							ORDER BY routes.id SEPARATOR ', ') AS Linien
							FROM stopsonroutes
							JOIN stops ON stopsonroutes.sid = stops.id
							JOIN routes ON stopsonroutes.rid = routes.id
							WHERE stops.name LIKE '" .$_GET['letters']. "%' 
							AND stops.id = stopsonroutes.sid
							AND routes.id = stopsonroutes.rid
							GROUP BY stopsonroutes.sid;";
				$result = mysql_query($query) OR die("Fehler: ". mysql_error());
			
				if (!mysql_num_rows($result)) {
					echo "Zu dieser Anfrage gibt es kein Ergebnis!\n";
				} else {
					echo "\t<table><tr><th>Haltestelle</th><th>Linie</th></tr>\n";
					while ($object = mysql_fetch_object($result)) {
						echo "\t<tr><td>$object->Haltestellen</td><td>$object->Linien</td></tr>\n";
					}
					echo "</table>\n";
				}
				mysql_free_result($result);
			}
			mysql_close($db);
		?>

		<form method="get" action="">
			<div>
				<B><p class='submenue'>Bitte geben Sie einen oder mehrere Anfangsbuchstaben der gesuchten Station ein!</p></B>
				<input name="letters" type="text" size="30" maxlength="30" />
				<input type="submit" value="Anzeigen" />
			</div>
		</form>
		</div>
	</body>
</html>