0

配列の値を表示したいのですが、配列のすべての値ではなく、配列の 1 つの値しか表示されません。

モデル:

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>
4

1 に答える 1

1

「foreach」ループをビューに移動する必要があります。現在、最初の $row を返し、foreach ループを停止しているためです (「return」はループを停止します)。

例:

意見

<?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

    }
于 2016-04-30T07:41:01.463 に答える