Am building a mini project on how to display a school broadsheet, i have try all i know best but no solution, please i need your help.
I have three tables Students, Scores, Subject.
This is how i want my display to look like.
Reg_no | Names of Students | Mathematics | English | Total | Average |
---|---|---|---|---|---|
TGD102 | Benjamin King | 60 | 55 | 115 | 57.5 |
TGD103 | David Mathew | 50 | 45 | 95 | 47.5 |
TGD104 | Mary James | 45 | 50 | 95 | 47.5 |
TGD105 | Solomom David | 70 | 45 | 115 | 57.5 |
I have try my little best but only was able to display it this way below
Reg_no | Student Names | Subject | marks |
---|---|---|---|
TGD102 | Benjamin King | Mathematics | 50 |
TGD103 | David Mathew | Mathematics | 45 |
TGD104 | Mary James | Mathematics | 35 |
TGD105 | Solomom David | Mathematics | 55 |
TGD102 | Benjamin King | English | 45 |
TGD103 | David Mathew | English | 35 |
TGD104 | Mary James | English | 40 |
TGD105 | Solomom David | English | 50 |
This was my code i used to display the table above.
<table id="myTable" class="table table-bordered table-striped">
<thead>
<th>Reg</th>
<th>Name</th>
<th>Subject</th>
<th>marks</th>
</thead>
<tbody>
<?php
include('db/conn.php');
$query=mysqli_query($conn,"select * from student,score,subject
where student.stu_id=score.scostu_id
AND score.scosbj_id=subject.subject_id ");
while($row2=mysqli_fetch_array($query)){
?>
<tr>
<td align="center"><?php echo $row2['stu_id']; ?></td>
<td><span style="text-transform:uppercase;"><?php echo $row2['name']; ?></span></td>
<td><span style="text-transform:uppercase;"><?php echo $row2['subject_title']; ?></span></td>
<td><span style="text-transform:uppercase;"><?php echo $row2['exam']; ?></span></td>
</tr>
<?php
}
?>
</tbody>
</table>
How can i modified the above code to give me some thing like this.
Reg_no | Names of Students | Mathematics | English | Total | Average |
---|---|---|---|---|---|
TGD102 | Benjamin King | 45 | 50 | 95 | 47.5 |
TGD103 | David Mathew | 50 | 45 | 95 | 47.5 |
TGD104 | Mary James | 60 | 30 | 90 | 45 |
TGD105 | Solomon Dvid | 35 | 50 | 85 | 42.5 |
2
Answers
This code is not optimize, but will do the job as you need.
Use following query to fetch the data in desired format
It will give an output similar to this
Modify your HTML code accordingly to accommodate for additional columns. Enjoy.