3

Student table Student table

Result table Result table

MY Question: Student table join result table ,but same student name display multiple, so My question I have same student display once

Model:

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();
}

Controller:

public function index(){
  $data = array(
            'page_title' => 'Result',
            'page_name' => 'result/result',
            'result'=>  $this->result_model->select()
        );
$this->load->view('admin/template', $data);
}

View

 <?php foreach ($result as $key => $value): ?>
                <tr>
                    <td><?php echo $value['first_name']; ?></td>
 <td><?php echo $value['mark']; ?></td>
</tr>
<?php endforeach;?>
1
  • 2
    You use Group By Clause. $this->db->group_by('student.student_id'); Commented Jul 7, 2016 at 6:30

2 Answers 2

3

You can use Group By for display your record as one time

Add This code in your model:

Model:

<?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();
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

@Nikunj Rathod I have create sudent marksheet and above result table in all columns join multiple table but student name,exam name,section name,standard id,subject name all columns duplicate, And I have to create view Below: student name, maths,physics,chemestry below result display kishan kakadiya,30,40,50
0

try this model code.

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();
}

3 Comments

result table in all columns join and display markshit ,but duplicate records return why?
Marksheet View Below:
student Name,subject 1,subject 2,...sunject n

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.