I have the following tables in my database. The tables midterm and finalterm contain marks of students.

Now I want to display a marks sheet of all the students in single page like following:

I know how to query in single table but I am facing problem in this case as there are three tables.
I am using Codeigniter, would you please kindly help me with what to code in my model and view file?
Thanks in advance 🙂
This is my Controller:
$this->load->model('Mod_student');
$data['records1']= $this->Mod_student->check1();
$this->load->view('view_student',$data);
Updated part
This is my view:
<?php if(count($records1) > 0) { ?>
<?php foreach ($records1 as $row){ ?>
<table>
<tr> <td><?php echo $row['StudentName']; ?></td></tr>
<tr>
<td><?php $midDate = explode(',',$row['MidDate']);
foreach($midDate as $md)
{
echo $md;
echo '<br />' ;
}
?>
</td>
<td><?php $midDate = explode(',',$row['MidSubject']);
foreach($midDate as $md)
{
echo $md;
echo '<br />' ;
}
?>
</td>
<td><?php $midDate = explode(',',$row['MidMarks']);
foreach($midDate as $md)
{
echo $md;
echo '<br />' ;
}
?>
</td>
</tr>
</table>
<?php } ?>
<?php } else { echo "No Record Found";} ?>
I have changed my view file and now it is working fine 🙂 But there are some problems that I am facing. If I run the above script I get the following output

If you notice my table midterm, you would see that the student whose id is 3 has got the same marks in both English and Maths. But in my output it displays mark for only one subject in the middle. Is it happening because you used distinct in your query? I have tried removing the distinct but then it does not show exact data.
Would you please kindly tell me how to fix the problem?
And thanks again for your help.:)
I have found a solution for you. It will fetch a single record for each student contining all of his information. I have used here GROUP_CONCAT of mysql. Therefore, on the php end you will have to explode the value and then access it in the loop. By the way here is the query you can run it like this.
OR Active Record Version
With distinct keyword. Here are some instructions to use this.
1. Every group concat should be exploded to be used at the php end. Like this
And Group Concat Item form query