$('#subject_stand').live('change',function(){
var dataSet={
ss_id:$(this).val(),
type:"stand_metric"
}
$.getJSON('include/select_sara_unit.php',dataSet,function(data){
if (data != null) {
$('#stand_detail').html(data[0].stand_name).fadeIn();
$('#subject_metric').html("<option value=''>กำหนดมาตรฐาน</option>");
var index=0;
//selectbox
$.each(data[0].mlist_id, function(i,json){
$('#subject_metric').append("<option value='"+data[0].mlist_id[index]+"'>ตัวชี้วัดที่ "+data[0].metric_no[index]+"</option>");
index++;
})//each
}
});//get
});//change
Code (PHP)
$stand_detail="select * from tb_sara_join_stand ss,m_standard stand
where ss.ss_id='".$_GET['ss_id']."'
and stand.stand_id=ss.stand_id";
$query_stand_de=mysql_query($stand_detail);
$count_stand=mysql_num_rows($query_stand_de);
$select_metric="select * from tb_metic_list ml,m_metric m
where ml.ss_id='".$_GET['ss_id']."'
and ml.metic_id=m.metric_id";
$query_metric=mysql_query($select_metric);
$count_metric=mysql_num_rows($query_metric);
$row_detail=mysql_fetch_array($query_stand_de);
$data_arr['stand_name']=$row_detail['stand_name'];
$col=0;
while($metric_row=mysql_fetch_array($query_metric))
{
$data_arr['mlist_id'][$col]=$metric_row['mlist_id'];
$data_arr['metric_no'][$col]=$metric_row['metric_no'];
$col++;
}
$arr[]=$data_arr;
header('Content-type:application/json;charset=utf-8');
echo json_encode($arr);