我的问题:学生表加入结果表,但同一个学生姓名显示多个,所以我的问题我有同一个学生一次显示
型号:
public function select(){
$this->db->select('*');
$this->db->from('result');
$this->db->join('student', 'result.student_id=student.student_id');
return $this->db->get()->result_array();
}
控制器:
public function index(){
$data = array(
'page_title' => 'Result',
'page_name' => 'result/result',
'result'=> $this->result_model->select()
);
$this->load->view('admin/template', $data);
}
查看
<?php foreach ($result as $key => $value): ?>
<tr>
<td><?php echo $value['first_name']; ?></td>
<td><?php echo $value['mark']; ?></td>
</tr>
<?php endforeach;?>
答案 0 :(得分:2)
您可以使用Group By
一次显示您的记录
在您的模型中添加此代码:
<强>型号:强>
<?php
Class Result_model extends CI_Model {
public function __construct() {
// Call the CI_Model constructor
parent::__construct();
}
public function select(){
$this->db->select('*');
$this->db->from('result');
$this->db->join('student', 'result.student_id=student.student_id');
$this->db->group_by('student.student_id');
return $this->db->get()->result_array();
}
}
答案 1 :(得分:0)
试试这个型号代码。
public function select(){
$this->db->select('*');
$this->db->join('student as st', 'st.student_id= re.student_id');
return $this->db->get('result as re')->result_array();
}