Buonasera ragazzi,la function funziona solo che mi stampa i modelli tutti sulla stessa riga della select (cioč in un unico option) che fare?
Grazie in anticipo.
Codice HTML:function aggiungi(){ var xhr=new XMLHttpRequest; var id="marche="+document.getElementById("marche").value; xhr.open("POST","ottieniModelli.php",true); xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xhr.onreadystatechange=function(){ if(xhr.readyState==4 && xhr.status==200){ nuovonodo=document.createElement('option'); testo=document.createTextNode(xhr.responseText); nuovonodo.appendChild(testo); modello.appendChild(nuovonodo); } } xhr.send(id); }Codice PHP:<?php
$marca=$_POST["marche"];
$pdo=new PDO("mysql:host=localhost; dbname=test","","");
$sql='SELECT count(modello) FROM modelli WHERE marca=:marca';
$result=$pdo->prepare($sql);
$result->bindValue(':marca',$marca);
$result->execute();
$somma=0;
foreach($result as $row){
$somma=$row['count(modello)'];
if($somma!=0){
$sql2='SELECT modello FROM modelli WHERE marca=:marca';
$result=$pdo->prepare($sql2);
$result->bindValue(':marca',$marca);
$result->execute();
foreach ($result as $row) {
echo $row['modello'];
}
}
else {
echo "modello standard";
}
}
?>

LinkBack URL
About LinkBacks


