<!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 Linie und Ausgabe ihrer Haltestellen in geordneter Reihenfolge</title>";
echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
echo "</head>";
echo "<body>";
echo "<h2>Auswahl einer Linie und Ausgabe ihrer Haltestellen in geordneter Reihenfolge</h2>
	Bitte w&auml;hlen Sie eine Sehensw&uuml;rdigkeit aus";
echo "<form action='' method='post'>";
echo "<select name='umfrage'>";
mysqli_select_db($dz, 'goettingen');
$sql = mysqli_query($dz, "SELECT DISTINCT idline FROM statline");
while ($ds = mysqli_fetch_object($sql)){
	$number = $ds -> idline;
/*	$id	  = $ds -> id;*/
	$idline[]=$number;
	}
$anzahl = count($idline);
for ($i = 0; $i < $anzahl; $i++){
	echo "<option value=\"$i\">$idline[$i]</option>";
	}	
echo "</select>";
echo "<input type='submit' value='Auswählen'>";
echo "</form>";
if (array_key_exists('umfrage',$_POST)) {
$line= $idline[$_POST['umfrage']];
$query="
SELECT name AS 'Haltestelle', ridesequence AS 'Reihenfolge'
FROM stations, statline
WHERE statline.idline = '". mysqli_real_escape_string($dz, $line) ."'
AND stations.id = statline.idstations 
ORDER BY statline.ridesequence ASC;";
$result=mysqli_query($dz, $query);
} else {
	$line ='';
}

if ($line != "") {
  if ($result) {
    echo "<p><span>Sie haben die Linie $line gew&auml;hlt:";
    echo "</span><p>";
    $rows=mysqli_num_rows($result);
    $cols=mysqli_num_fields($result);
    for ($r=0; $r<$rows; $r++){
      for ($c=0; $c<1; $c++){
	    echo mysqli_result($result, $r, $c);
        echo "<br>";	  
      }
    }
    echo "</p>";
  }
} 
echo "</body>";
?>
