보기 및 ClassID가에 결과를 표시하지하지만 난 배열을foreach 루프는 CodeIgniter는 내가 studentIDs으로 출석 주석의 여러 레코드를 얻을 시도하고
배열 ([0] => 배열 ([0] = 인쇄 할 때 > [stdClass Object ([attendanceID] => 90 [comment] => 이것은 자라 버트입니다.) [2] => 배열 ([0] => stdClass 객체 ([attendanceID] => 91 [comment] => 이것은 ibrahim입니다. ([참석자 ID] => 93 [코멘트] =>)) [5] => 배열 ([0] => 92) stdClass 객체 ([attendanceID] => 94 [comment] =>)) [6] => 배열 ([0] => stdClass 객체 ([attendanceID ([attendanceID] => 96 [comment] =>))))
하지만 인쇄 할 수 없습니다. .. Foreach 루프 아무것도 쇼를 사용하여보기 내가 뭘 어디서 모르는 잘못된
Controllor
$studentID = []; // Multiple Student ids
$comments = [];
$this->data['set'] = $id; //class id
$this->data['students'] = $this->student_m->get_order_by_student(array('classesID' => $id, 'schoolyearID' => $schoolyearID));
foreach($this->data['students'] as $key => $val){
$studentID[] = $val->studentID; //
}
foreach ($studentID as $student) {
$comments[] = $this->sattendance_m->get_comment($id,$student);
}
$this->data['comments']= $comments;
print_r($comments);
모델
function get_comment($id,$student) {
$this->db->select('attendanceID,comment');
$this->db->where('classesID', $id);
$this->db->where_in('studentID', $student);
$this->db->order_by($this->_primary_key,"desc");
$this->db->limit(1);
$this->db->from($this->_table_name);
$query=$this->db->get();
return $query->result();
}
당신이
print_r
의 출력을 볼 수 있듯이3210
보기
<?php
if(count($comments)) {
foreach ($comments as $key => $row) {
echo $row->comment;
}
}?>
후 전체 컨트롤러 코드해야 내부 루프를 할 필요가있다. if (count ($ comments)) {} –
대신에 if ($ comments) {}를 체크하여 귀하가 퀘스트에 언급 한 컨트롤러 전체를 추가하십시오. – Gagantous
당신은 print_r을 사용하고 있습니까? 컨트롤러에서 어레이를보기 위해 전달하는 데 사용했던 방법은 무엇입니까? – Gagantous