2016-04-30 66 views
0

我想顯示數組的值,但它只顯示數組的一個值而不是數組的所有值。Codeigniter數組顯示

型號:

function get_subject_position($exam_id , $class_id , $subject_id) { 

     $this->db->where('exam_id' , $exam_id); 
     $this->db->where('class_id' , $class_id); 
     $this->db->where('subject_id' , $subject_id); 
     $this->db->select('mark_obtained'); 
     $this->db->order_by('mark_obtained DESC'); 
     $subject_position = $this->db->get('mark')->result_array(); 
     foreach($subject_position as $row) { 

      return $row;  
     } 
     } 

查看:

$subject_pos = $this->crud_model->get_subject_position($row2['exam_id'], $class_id, $row3['subject_id']); 

<td style="text-align: center;"><?php echo $subject_pos['mark_obtained'];?></td> 

回答

1

您需要的 「foreach」 循環進入您的看法,因爲現在它的返回首$行,然後停止在foreach環路( 「返回」 停止循環)

實施例:

查看

<?php 
$subject_pos = $this->crud_model->get_subject_position($row2['exam_id'], $class_id, $row3['subject_id']); 
foreach($subject_pos as $row) { 
?> 
<tr> 
    <td style="text-align: center;"><?=$row['mark_obtained']?></td> 
</tr> 
<?php } ?> 

功能

function get_subject_position($exam_id , $class_id , $subject_id) { 

    $this->db->where('exam_id' , $exam_id); 
    $this->db->where('class_id' , $class_id); 
    $this->db->where('subject_id' , $subject_id); 
    $this->db->select('mark_obtained'); 
    $this->db->order_by('mark_obtained DESC'); 

    return $this->db->get('mark')->result_array(); // Get ALL rows 

    } 
+0

你does'n結果發送陣列return語句應該是這樣的回報$這個 - > DB->獲得( '標記') - > result_array(); –

+0

@RanjeetSingh謝謝,更新了代碼 – prasoc

+0

非常感謝 – 4Jean