Reputation: 463
I am trying to get sections of collage from a MySQL database using PHP and jQuery.
I am getting data normal, but I get an error when I use html()
to add the result to a div
Here is my code:
$("#collage_id").on('change',function(e){
$("#sections").fadeOut(1200);
if(this.value==0){
$("#sections").fadeOut(1200);
}
else {
<?PHP
$collage_sections=new DataBase();
$sections=$collage_sections->get_sections();
$sections_checkbox="";
while($section=mysqli_fetch_array($sections)){
$sections_checkbox.="<label class='checkbox-inline'><input type='checkbox' value='$section[0]'>$section[1]</label>";
}
?>
$("#sections").html(<?PHP echo $sections_checkbox; ?>).fadeIn(1200);
}
});
Does anyone have any help or ideas?
Upvotes: 2
Views: 665
Reputation: 4825
As @Swellar says, wrap the $sections_checkbox
variable in quotes. At the moment, javascript sees it as a variable instead of a string which is what you want. As a tip, always work with your console in the browser. You'll find answers to most syntax errors. To fix your error, do this instead.
$("#sections").html("<?php echo $sections_checkbox; ?>").fadeIn(1200);
Upvotes: 4