2

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?

0

1 Answer 1

4

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.