0

2つのクエリのnum行を比較しようとしていますが、値は配列からのものです。しばらくの間、phpを使用します。

$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());


                                $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){

                        $status['status'] = "Incomplete";
                    }else{

                        $status['status'] = "Complete";
                    }


                    $full_data = array(

                        'info' => $data,
                        'status'=>$status

                        );


        echo json_encode($full_data);

    }

コンソールを確認したところ、すべてのステータスが1つしか表示されておらず、コンソールから次のようなエラーが表示されます。

TypeError: info[i] is undefined
[Break On This Error] 

何が起こっていますか?

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) {

        var info = data.info;
        var status = data.status;

        html = "<tr>";

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




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

           }
      });

   }
   get_sections_status();           
4

1 に答える 1

0

まず、あなたがやりたいことは、ループにステータスクエリを追加することだと思います。また、Javascript を少し簡単にするために、データにステータスを追加しました。

$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());


$data=array();

while ($row = mysql_fetch_array($result)){
    $temp =    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 = '$row['section_level']' ";


    $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){
        $temp['status'] = "Incomplete";
    }else{
        $temp['status'] = "Complete";
    }
    $data[] = $temp;
}




$full_data = array(
   'info' => $data,
);


    echo json_encode($full_data);

}

今JSで。(これをチェックしていません。data.info.length は単に data.length である可能性があります)

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){
        for(var i = 0 ; i>data.info.length ; i++) {
           var info = data.info[i];

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

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

       }
   });
}
get_sections_status();
于 2013-01-25T17:39:58.303 に答える