Michaela93
Grünschnabel
Hallo Zusammen,
folgendes Problem, dass mich martert.
Wir haben hier ein Dropdown-Menü, bei der die Filtrierung nicht funktioniert.
Das Problem liegt an "WHERE hersteller = '".$_POST["query"]."'"
der ajax-loop loopt nicht so wie ich das will.
Er soll da, das posten, was in "hersteller" ausgewählt worden ist.
Bitte um Unterstützung.
LG
Michi
folgendes Problem, dass mich martert.
Wir haben hier ein Dropdown-Menü, bei der die Filtrierung nicht funktioniert.
Das Problem liegt an "WHERE hersteller = '".$_POST["query"]."'"
der ajax-loop loopt nicht so wie ich das will.
Er soll da, das posten, was in "hersteller" ausgewählt worden ist.
Bitte um Unterstützung.
LG
Michi
HTML:
<?php
//index.php
$connect = mysqli_connect("localhost", "xxx", "xxx", "xxx");
$hersteller = '';
$query = "SELECT hersteller FROM verwendung GROUP BY hersteller ORDER BY hersteller ASC";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result))
{
$hersteller .= '<option value="'.$row["hersteller"].'">'.$row["hersteller"].'</option>';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<form method="post" id="anfrage" action="fetch.php" >
<div id="suche1">
<div>
<select name="hersteller" id="hersteller" class="Feld action">
<option value="hersteller">Hersteller</option><?php echo $hersteller ?></select>
<select name="hubraum" id="hubraum" class="Feld action"><option value="">Hubraum</option></select>
<select name="modell" id="modell" class="Feld action"><option value="">Modell</option></select>
<select name="spezifikation" id="spezifikation" class="Feld action"><option value="">Spezifikation</option></select>
</div>
</div>
</form>
</body>
</html>
<script>
$(document).ready(function(){
$('.action').change(function(){
if($(this).val() != '')
{
var action = $(this).attr("id");
var query = $(this).val();
var result = '';
if (action == "hersteller"){result = 'hubraum';}
if (action == "hubraum") {result = 'modell';}
if (action == "modell"){result = 'spezifikation';}
if (action == "spezifikation"){result = 'pordukta';}
$.ajax({
url:"sml.php",
method:"POST",
data:{action:action, query:query},
success:function(data){
$('#'+result).html(data);
}
})
}
});
});
</script>
PHP:
<?php
//sml.php
if(isset($_POST["action"]))
{
$connect = mysqli_connect("localhost", "xxx", "xxx", "xxx");
$output = '';
if($_POST["action"] == "hersteller")
{
$query = "SELECT hubraum FROM verwendung WHERE hersteller = '".$_POST["query"]."' GROUP BY hubraum";
$result = mysqli_query($connect, $query);
$output .= '<option value="">Hubraum</option>';
while($row = mysqli_fetch_array($result))
{
$output .= '<option value="'.$row["hubraum"].'">'.$row["hubraum"].'</option>';
}
}
//
//
// hier folgt die besagte Stelle
//
//
if($_POST["action"] == "hubraum")
{
$query = "SELECT modell FROM verwendung WHERE hersteller = '".$_POST["query"]."' AND hubraum = '".$_POST["query"]."'";
$result = mysqli_query($connect, $query);
$output .= '<option value="">Modell</option>';
while($row = mysqli_fetch_array($result))
{
$output .= '<option value="'.$row["modell"].'">'.$row["modell"].'</option>';
}
}
if($_POST["action"] == "modell")
{
$query = "SELECT spezifikation FROM verwendung WHERE modell = '".$_POST["query"]."'";
$result = mysqli_query($connect, $query);
$output .= '<option value="">Spezifikation</option>';
while($row = mysqli_fetch_array($result))
{
$output .= '<option value="'.$row["spezifikation"].'">'.$row["spezifikation"].'</option>';
}
}
if($_POST["action"] == "spezifikation")
{
$query = "SELECT produkta FROM verwendung WHERE spezifikation = '".$_POST["query"]."'";
$result = mysqli_query($connect, $query);
$row = mysqli_fetch_array($result);
$insert = $row["produkta"];
$output1 = explode(',', $insert);
foreach($output1 as $like){
$query2 = "SELECT * FROM artikel WHERE artikelnummer = '".$like."'";
echo '<div>'.$like.'</div>';
}
}
echo $output;
}
?>