BumBumBoris: 3 Selectboxen verknüpfen

Beitrag lesen

Hi!

Hier mal der gesamte Quellcode der Seite, die ich bislang erstellt habe:

<?php
echo "<form name="search" method="POST" action="./index.php?id=10">";
echo "<h1>Suche</h1>";
echo "<ol>";
echo "<li>Hersteller des Fahrzeuges auswählen";
echo "<li>Fahrzeugtyp auswählen";
echo "<li>Modell auswählen<br>&nbsp;<br>";
echo "</ol>";
echo "<table width="80%" cellspacing=2 cellpadding=2 border=0>";
 echo "<tr>";
  echo "<td id=suche width="30%" valign="top">";
    echo "<b>Kategorie:</b>";
  echo "</td>";
   echo "<td id=suche valign=top>";
   echo "<select name="kategorie" size="1" onChange="redirect(this.options.selectedIndex)">";
    echo "<option selected>Bitte wählen Sie aus...</option>";
    echo "<option>PKW</option>";
     echo "<option>NKW</option>";
     echo "<option>Motorräder</option>";
    echo "</select>";
   echo "</td>";
 echo "</tr>";
 echo "<tr>";
  echo "<td id=suche width="30%" valign="top">";
    echo "<b>Hersteller:</b>";
  echo "</td>";
   echo "<td id=suche valign=top>";
   echo "<select name="hersteller" size="1">";
    echo "<option selected>Bitte wählen Sie aus...</option>";
    echo "</select>";
   echo "</td>";
 echo "</tr>";
 echo "<tr>";
   echo "<td id=suche width="30%" valign="top">";
    echo "<b>Fahrzeugtyp:</b>";
  echo "</td>";
  echo "<td id=suche valign=top>";
   echo "<select  name="fahrzeugtyp" size="1">";
   echo "<option selected>Bitte wählen Sie aus...</option>";
    echo "</select>";
   echo "</td>";
 echo "</tr>";
 echo "<tr>";
   echo "<td id=suche width="30%" valign="top">";
    echo "<b>Modellreihe:</b>";
  echo "</td>";
  echo "<td id=suche valign=top>";
   echo "<select name="modell" size="1" >";
   echo "<option selected>Bitte wählen Sie aus...</option>";
    echo "</select>";
   echo "</td>";
 echo "</tr>";
echo "</table>";

// Hier werden sechs Arrays in Javascript erzeugt, denen später ein PHP Array zugewiesen wird.
echo "<script>";
echo "var pkw_array = new Array()"; // Array für PKW's
echo "</script>";
echo "<script>";
echo "var nkw_array = new Array()"; // Array für NKW's
echo "</script>";
echo "<script>";
echo "var motorrad_array = new Array()"; // Array für Motorräder
echo "</script>";
$pkw = array(); // PHP Array für pkw
$nkw = array(); // PHP Array für nkw
$motorrad = array(); // PHP Array für motorräder
$p = 0; // Zählvariable für die Arrays der pkw
$n = 0; // Zählvariable für die Arrays der nkw
$m = 0; // Zählvariable für die Arrays der motorräder

$query1 = "Select Distinct Hersteller from z_zuordnung_pkw group by Hersteller";  // SQL-Statement erstellen
$query2 = "Select Distinct Hersteller from z_zuordnung_nkw group by Hersteller"; // SQL-Statement erstellen
$query3 = "Select Distinct Hersteller from z_zuordnung_motorrad group by Hersteller"; // SQL-Statement erstellen
$result1 = mysql_query($query1);
$result2 = mysql_query($query2);
$result3 = mysql_query($query3);
$text = "Bitte wählen Sie aus...";
$pkw[$p] = $text;
$nkw[$n] = $text;
$motorrad[$m] = $text;
echo "<script>";
echo "pkw_array["$p"] = "$pkw[$p]"";
echo "</script>";
echo "<script>";
echo "nkw_array["$n"] = "$nkw[$n]"";
echo "</script>";
echo "<script>";
echo "motorrad_array["$m"] = "$motorrad[$m]"";
echo "</script>";
$p = 1;
$n = 1;
$m = 1;
while($row1 = mysql_fetch_array($result1))     // Array für PKW
 {
  $pkw[$p] = $row1[0];
  echo "<script>";
  echo "pkw_array["$p"] = "$pkw[$p]"";
  echo "</script>";
  $p = $p + 1;
 }

while($row2 = mysql_fetch_array($result2))     // Array für Motorradbatterien füllen
 {
  $nkw[$n] = $row2[0];
  echo "<script>";
  echo "nkw_array["$n"] = "$nkw[$n]"";
  echo "</script>";
  $n = $n + 1;
 }

while($row3 = mysql_fetch_array($result3))     // Array für Antrieb und Beleuchtung füllen
 {
  $motorrad[$m] = $row3[0];
  echo "<script>";
  echo "motorrad_array["$m"] = "$motorrad[$m]"";
  echo "</script>";
  $m = $m + 1;
 }

echo "</form>";
mysql_close();
?>

<script>
var groups=document.search.kategorie.options.length
var group=new Array(groups)
var temp = new Array()

for (i=0; i<groups; i++)
group[i]=new Array()

for (i=0; i<<? echo $p; ?>; i++){
 group[1][i] = new Option(pkw_array[i])
}

for (i=0; i<<? echo $n; ?>; i++){
 group[2][i] = new Option(nkw_array[i])
}

for (i=0; i<<? echo $m; ?>; i++){
 group[3][i] = new Option(motorrad_array[i])
}

var temp=document.search.hersteller

function redirect(x){
for (m=temp.options.length-1;m>0;m--)
 temp.options[m]=null
  for (i=0;i<group[x].length;i++){
   temp.options[i]=new Option(group[x][i].text,group[x][i].value)
  }
 temp.options[0].selected=true
}

function go(){
location=temp.options[temp.selectedIndex].value
}

</script>

Gruß
BumBumBoris

PS: es ist auch nicht nötig, dass du mein ganzes Posting zitierst ;) Ich weiss was ich geschrieben habe *g*

liebe Grüße aus Berlin
lina-