<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
<?php
require_once('mysql.inc.php');
echo "<head>";
echo "<title>Auswahl einer Haltestelle und Ausgabe der haltenden Linien und ihrer Farbe</title>";
echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
echo "</head>";
echo "<body>";
echo "<h2>Auswahl einer Haltestelle und Ausgabe der haltenden Linien und ihrer Farbe</h2>";
echo "<form action='' method='post'>";
echo "Haltestelle :";
echo "<select name='umfrage'>";
mysqli_select_db($dz, 'goettingen');
$sql = mysqli_query($dz, "SELECT * FROM stations");
while ($ds = mysqli_fetch_object($sql)){
  $name = $ds -> name;
  $id  = $ds -> id;
  $station[]=$name;
  $id1[]=$id;
  }
$anzahl = count($station);
for ($i = 0; $i < $anzahl; $i++){
  echo "<option value=\"$i\">$station[$i]</option>";
  }
echo "</select>";
echo "<input type='submit' value='Auswählen'>";
echo "</form>";
if (array_key_exists('umfrage',$_POST)) {
$station= $station[$_POST['umfrage']];
$query="
SELECT line.name AS 'linie', line.color AS 'Farbe', hexa
FROM line
WHERE line.id
IN (
SELECT statline.idline
FROM statline
WHERE statline.idstations = (
SELECT DISTINCT stations.id
FROM stations
INNER JOIN statline ON stations.id = statline.idstations
WHERE stations.name LIKE '". mysqli_real_escape_string($dz, $station) ."'
)
);";
$result=mysqli_query($dz, $query);
} else {
	$station ='';
}
if ($station != ""){
  echo "Sie haben als Station: <b>$station</b> gew&auml;hlt<br>";
  while ($ds = mysqli_fetch_object($result)){
    $linie = $ds -> linie;
    $color  = $ds -> Farbe;
    $hexa  = $ds -> hexa;
    echo 
    "<table border=0>
    <tr>
    <td width=70 height=20><b>$linie</b></td>
    <td width=70 height=20 bgcolor=$hexa><font color=white>$color</font></td>
    </tr>
    </table>";
    }
  mysqli_close($dz);
  } 
echo "</body>";
?>
