gmc1103's post in Help with dynamic multiple select was marked as the answer
February 12, 2016
I have fixed using
if($val!=null){
try {
$sql = "SELECT t1.`user_proc`, t1.`user_name` FROM `esmaior_alunos` as t1
INNER JOIN `esmaior_turma` as t2 ON (t1.`user_id_ano_turma` = t2.`id_turma`)
WHERE (t2.`id_turma` = :val);";
$query = $DB_con->prepare($sql);
$query->bindparam(":val", $val);
$query->execute();
$result = $query->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
echo "<option value='{$row['user_proc']}'>{$row['user_name']}</option>\n";
}
} catch (PDOException $e) {
echo $e->getMessage();
}
}
and the ajax
<script>
$(document).on("change", '#turma', function(e) {
var turmas = $(this).val();
$.ajax({
type: 'post',
url: 'classes/getFromDatabase.php',
data: {get_option:turmas},
dataType: 'html',
success: function(resposta) {
console.log(resposta);
document.getElementById("alunos").innerHTML=resposta;
}
});
});
</script>
For those with same problem