Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,




I have a table with data like below
rollno subject 	marks
1		english  	98
2		english  	90
3		english  	83	
1		maths  		89
2		maths  		75
3		maths  		67	
1		physics  	76
2		physics  	68
3		physics  	59	


I want to display in codeigniter view like below
rollno 	english		maths	physics
1		98			89		76
2		90			75		68
3		83			67		59


Please help.

What I have tried:

Controller:

PHP
$data['subjects'] = $mmodel->distinct()
->select('b.id as subjectid, b.subject')
->join('tblsubjects b','b.id = tblexammarks.subjectid','left')
->where('examid',$examid)->findAll();
										
$data['marks'] = $mmodel->select('rollno,subjectid,(theory_marks + viva_marks) as obmarks')
->where('examid',$examid)
->orderBy('rollno')
->findAll();
        
return  view('exammarks/exmarksbysubs',$data);



View:

PHP
<table class="table table-striped table-bordered">
    <tr>
        <td>Rollno</td>
        <?php  if (isset($subjects)) {
        foreach($subjects as $row1){ ?>
            <td><?=$row1['subject'];?></td>
        <?php } }?>
    </tr>
 
        foreach($marks as $row) { 
        <td><?=$row['rollno']; </td>      
        <td><?= $row['obmarks']; ?> </td>   
 </tr> <?php } ?>
</table>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900