Ragazzi vi posto il codice che ho scritto. Non riesco a capire cosa sbaglio se qualcuno potesse darmi una mano gliene sarei riconoscente.
L'errore dovrebbe essere in menudin.php ma per sicurezzo vi posto tutto
//Prodotti,php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name = "author" lang = "it" content = "Dal Porto Samuele">
<meta http-equiv = "Expires" content = "">
<meta http-equiv = "Content-Type" content = "text/html; charset=ISO-8859-1">
<title>Venditore</title>
<link rel="stylesheet" href="./stili/Stili.css" type="text/css" media="screen">
<script type="text/javascript" src="./js/menu_din.js"></script>
</head>
<body >
<?php include("menu.php"); ?>
<div class="selettori">
<form action="">
<a >Prezzo</a><br>
<select name="Prezzo">
<option value="null"> ---------- </option>
<option value="0"> meno di 100 </option>
<option value="100"> tra 100 e 300 </option>
<option value="300"> tra 300 e 500 </option>
<option value="500"> tra 500 e 700 </option>
<option value="700"> tra 700 e 900 </option>
<option value="900"> oltre i 900 </option>
</select>
</form>
<form action="">
<a>Tipologia</a> <br>
<select onChange="crea_menu(this.value)" name="Tipologia">
<option value="null"> ---------- </option>
<?php
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("azienda", $con);
$sql="SELECT DISTINCT Tipo FROM prodotti";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo "<option value = \" ".$row["Tipo"]."\"> ".$row["Tipo"]."</option>";
}
mysql_close($con);
?>
</select>
</form>
<div id="menu_din">ciao<br><br></div>
</div>
</body>
</html>
//menudin.php
<?php
$param=$_GET["q"];
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("azienda", $con);
$nomi = mysql_query("SELECT * FROM campi WHERE Tipo = \"".$param."\"");
$title = mysql_fetch_array($nomi);
for( $i = 1 ; $i <= 4 ; $i++)
{
echo "<form action=''>";
echo "<select name='".$title['CAT'.$i]."'>";
echo "<a>" . $title['CAT'.$i] . "</a><br>";
echo "<option value=\"null\"> ---------- </option>";
//$categoria = mysql_query($cat);
$cat=mysql_query("SELECT DISTINCT CAT".$i." FROM prodotti WHERE Tipo = '".$param."'");
while($row = mysql_fetch_array($cat))
{
echo "<option value = \" ".$row["CAT".$i]."\"> ".$row['CAT'.$i]."</option>";
}
echo "</select>";
echo"</form>";
}
mysql_close($con);
?>
//menu_din.js
function crea_menu(param){
var xmlHttp;
try { xmlHttp=new XMLHttpRequest(); } //(1)
catch (e) {
try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } //(2)
catch (e) {
try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) {
window.alert("Il tuo browser non supporta AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4) {
document.getElementById("menu_din").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open('GET',"menudin.php?q="+param,true);
xmlHttp.send(null);
}
Vi ringrazio anticipatamente
L'errore dovrebbe essere in menudin.php ma per sicurezzo vi posto tutto
//Prodotti,php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name = "author" lang = "it" content = "Dal Porto Samuele">
<meta http-equiv = "Expires" content = "">
<meta http-equiv = "Content-Type" content = "text/html; charset=ISO-8859-1">
<title>Venditore</title>
<link rel="stylesheet" href="./stili/Stili.css" type="text/css" media="screen">
<script type="text/javascript" src="./js/menu_din.js"></script>
</head>
<body >
<?php include("menu.php"); ?>
<div class="selettori">
<form action="">
<a >Prezzo</a><br>
<select name="Prezzo">
<option value="null"> ---------- </option>
<option value="0"> meno di 100 </option>
<option value="100"> tra 100 e 300 </option>
<option value="300"> tra 300 e 500 </option>
<option value="500"> tra 500 e 700 </option>
<option value="700"> tra 700 e 900 </option>
<option value="900"> oltre i 900 </option>
</select>
</form>
<form action="">
<a>Tipologia</a> <br>
<select onChange="crea_menu(this.value)" name="Tipologia">
<option value="null"> ---------- </option>
<?php
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("azienda", $con);
$sql="SELECT DISTINCT Tipo FROM prodotti";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo "<option value = \" ".$row["Tipo"]."\"> ".$row["Tipo"]."</option>";
}
mysql_close($con);
?>
</select>
</form>
<div id="menu_din">ciao<br><br></div>
</div>
</body>
</html>
//menudin.php
<?php
$param=$_GET["q"];
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("azienda", $con);
$nomi = mysql_query("SELECT * FROM campi WHERE Tipo = \"".$param."\"");
$title = mysql_fetch_array($nomi);
for( $i = 1 ; $i <= 4 ; $i++)
{
echo "<form action=''>";
echo "<select name='".$title['CAT'.$i]."'>";
echo "<a>" . $title['CAT'.$i] . "</a><br>";
echo "<option value=\"null\"> ---------- </option>";
//$categoria = mysql_query($cat);
$cat=mysql_query("SELECT DISTINCT CAT".$i." FROM prodotti WHERE Tipo = '".$param."'");
while($row = mysql_fetch_array($cat))
{
echo "<option value = \" ".$row["CAT".$i]."\"> ".$row['CAT'.$i]."</option>";
}
echo "</select>";
echo"</form>";
}
mysql_close($con);
?>
//menu_din.js
function crea_menu(param){
var xmlHttp;
try { xmlHttp=new XMLHttpRequest(); } //(1)
catch (e) {
try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } //(2)
catch (e) {
try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) {
window.alert("Il tuo browser non supporta AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4) {
document.getElementById("menu_din").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open('GET',"menudin.php?q="+param,true);
xmlHttp.send(null);
}
Vi ringrazio anticipatamente