hey guys im trying to compare 2 num_rows the append the result on the $data array then access it via ajax.

 $get_section = "SELECT *
                        FROM section a
                        LEFT JOIN advisory_sections b ON(a.section_id = b.section_id)
                        LEFT JOIN school_faculty c ON (b.faculty_id = c.faculty_id)

                        WHERE a.school_id = '$school_id'  ORDER BY section_level ASC";





                        $result=mysql_query($get_section)or die(mysql_error());

                            $i=0;

                                $data=array();
                    while ($row = mysql_fetch_array($result))
                                {
                                    $data[] = array(
                                       'sec_id'=>$row['section_id'],
                                       'sec_name'=>$row['section_name'],
                                       'sec_dept'=>$row['section_department'],
                                       'sec_lvl'=>$row['section_level'],
                                      'advisory_id'=>$row['advisory_id'],
                                      'first_name'=>$row['f_firstname'],
                                      'last_name'=>$row['f_lastname'],
                                      'middle_name'=>$row['f_middlename'],
                                      'advisor_id'=>$row['faculty_id'],
                                    );


                    $get_subjects = "SELECT subject_name
                                        FROM subjects  
                                        WHERE level = '$data.sec_lvl' ";


                        $result_get_subjects =mysql_query($get_subjects)or die(mysql_error());

                        $subjects_count = mysql_num_rows($result_get_subjects);


                    $check_archive_subjects = " SELECT b.subject_name 
                                                FROM registrar_grade_archive a
                                                LEFT JOIN subjects b ON(a.subject_id=b.subject_id)
                                                WHERE a.advisor_faculty_id = '$data.advisor_id'
                                                GROUP BY b.subject_name ASC
                                                 " ;

                     $query_checking =mysql_query($check_archive_subjects)or die(mysql_error());

                    $subjects_count_sent = mysql_num_rows($query_checking);



                                if($subjects_count_sent == $subjects_count){

                                        $data[] = array(

                                            'status' => "Complete"  

                                            );
                                    }else{

                                        $data[] = array(

                                            'status' => "Incomplete"    

                                            );
                                    }


                                $i++;
                                }


        echo json_encode($data);

AJAX:

    function get_sections_status(){
             $.ajax({                
             url: 'teacher_class_get.php',
            dataType: 'json',
           type: 'POST', //u missed this line.
            data:{'func_num':'6'},
            success: function (data){
              $.each(data, function(i, item) {





        html = "<tr>";

                              html += "<td style='width:10%;'><input type='radio' name='section_id' rel='"+data[i].advisory_id+"' value='"+data[i].sec_id+"'></td>";
                              html += "<td style='width:25%;'><label>"+data[i].status+"</label></td>";
                              html += "<td style='width:15%;'><label id='year_level' rel='"+data[i].sec_lvl+"''>"+data[i].sec_lvl+"</label></td>";
                              html += "<td style='width:20%;'><label>"+data[i].sec_name+"</label></td>";
                              html += "<td style='width:30%;'><label id='faculty_id' rel='"+data[i].advisor_id+"'>"+data[i].last_name+", "+data[i].first_name+" "+data[i].middle_name+"</label></td>";                              
                              html += "</tr>";




       $('#table-sections-content').append(html);
       });

           }
      });

   }
   get_sections_status();

and im getting this response:

[{"sec_id":"24","sec_name":"laglag piso","sec_dept":"highschool","sec_lvl":"firstyear","advisory_id":"52","first_name":"Mario","last_name":"Lopez","middle_name":"C","advisor_id":"2"},{"status":"Complete"},{"sec_id":"36","sec_name":"black","sec_dept":"highschool","sec_lvl":"firstyear","advisory_id":"60","first_name":"asdf","last_name":"asdf","middle_name":"asdf","advisor_id":"1"},{"status":"Complete"},{"sec_id":"32","sec_name":"level-up","sec_dept":"highschool","sec_lvl":"firstyear","advisory_id":"53","first_name":"asdf","last_name":"asdf","middle_name":"asdf","advisor_id":"1"},{"status":"Complete"},{"sec_id":"31","sec_name":"penguin","sec_dept":"elementary","sec_lvl":"grade1","advisory_id":"55","first_name":"Mario","last_name":"Lopez","middle_name":"C","advisor_id":"2"},{"status":"Complete"},{"sec_id":"17","sec_name":"manggagancho","sec_dept":"elem","sec_lvl":"grade1","advisory_id":"54","first_name":"asdf","last_name":"asdf","middle_name":"asdf","advisor_id":"1"},{"status":"Complete"},{"sec_id":null,"sec_name":null,"sec_dept":null,"sec_lvl":"grade1","advisory_id":null,"first_name":null,"last_name":null,"middle_name":null,"advisor_id":null},{"status":"Complete"},{"sec_id":"35","sec_name":"asdfasdf","sec_dept":"elementary","sec_lvl":"grade1","advisory_id":"58","first_name":"Yuki","last_name":"Onamoto","middle_name":"Parlson","advisor_id":"7"},{"status":"Complete"},{"sec_id":null,"sec_name":null,"sec_dept":null,"sec_lvl":"grade2","advisory_id":null,"first_name":null,"last_name":null,"middle_name":null,"advisor_id":null},{"status":"Complete"},{"sec_id":null,"sec_name":null,"sec_dept":null,"sec_lvl":"grade3","advisory_id":null,"first_name":null,"last_name":null,"middle_name":null,"advisor_id":null},{"status":"Complete"},{"sec_id":null,"sec_name":null,"sec_dept":null,"sec_lvl":"grade4","advisory_id":null,"first_name":null,"last_name":null,"middle_name":null,"advisor_id":null},{"status":"Complete"},{"sec_id":"25","sec_name":"ketchup","sec_dept":"highschool","sec_lvl":"secondyear","advisory_id":"56","first_name":"Mario","last_name":"Lopez","middle_name":"C","advisor_id":"2"},{"status":"Complete"},{"sec_id":"26","sec_name":"west side","sec_dept":"highschool","sec_lvl":"thirdyear","advisory_id":"59","first_name":"asdf","last_name":"asdf","middle_name":"asdf","advisor_id":"1"},{"status":"Complete"},{"sec_id":"27","sec_name":"palos","sec_dept":"highschool","sec_lvl":"thirdyear","advisory_id":"57","first_name":"Mario","last_name":"Lopez","middle_name":"C","advisor_id":"2"},{"status":"Complete"}]

i guess my coding is wrong cuz supposedly im not going to get {"status":"Complete"}. second im getting un defined from my out put. please help guys. tnx in advance

Member Avatar for LastMitch

@aoi.serizawa.9

i guess my coding is wrong cuz supposedly im not going to get {"status":"Complete"}. second im getting un defined from my out put. please help guys. tnx in advance

When you ran this code what error you get? Those results doesn't seem like it's related to the PHP side. It's more javascript (AJAX). When you run a PHP code, it usually tell you an error of which line in the PHP code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.