我正在尝试使用 php 在我的数组中推送新值
$select_all_schools = "SELECT * FROM schools ";
$query = mysql_query($select_all_schools) OR die(mysql_error());
while($row = mysql_fetch_array($query)){
$item=array(
'school_name' => $row['school_name'],
'school_address' => $row['school_address'],
'school_id' => $row['school_id'],
);
$select_sections = "SELECT * FROM section WHERE school_id = '".$row['school_id']."'";
$query_section = mysql_query($select_sections) or die(mysql_error());
$sections_counts = mysql_num_rows($query_section);
$select_sections_deped_archive = "SELECT * FROM deped_grade_archive
WHERE school_id = '".$row['school_id']."'
GROUP BY section_id ";
$query_section_deped_archive = mysql_query($select_sections_deped_archive) or die(mysql_error());
$sections_counts_grade_archive = mysql_num_rows($query_section_deped_archive);
if($sections_counts_grade_archive == $sections_counts ){
$item['stat'] = 'Complete';
}
else{
$item['stat'] ='Incomplete';
}
}
echo json_encode($item);
然后使用ajax获取值
function get_all_school_status(){
$.ajax({
type:'POST',
url:'deped_functions.php',
dataType:'json',
data:{'func_num':'1'},
success:function (data){
$.each(data, function(i, item) {
html = "<tr>";
html += "<td style='width:20%;'><input type='radio' name='school_id' value='"+data[i].school_id+"'></td>";
html += "<td style='width:25%;'><label>"+data[i].stat+"</label></td>";
html += "<td style='width:55%;'><label >"+data[i].school_name+"</label></td>";
html += "</tr>";
$('#table-schools-content').append(html);
});
}
});
}
get_all_school_status();
但不幸的是,尽管我的控制台显示我正确地将值从 php 获取到 ajax,但我得到了未定义的值。我做错了什么?..请帮助大家。tnx 提前