Click here to Skip to main content
15,794,240 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I want to display Students results of each student all subject marks should be in one row wise format.

My Controller is:

PHP
public function marksall() {
$class_id = $this->input->post('class_id');         
$exam_id = $this->input->post('exam_id');
$this->data['subjects'] = $this->mark->get_subject_list_all($exam_id, $class_id, $section_id);
$this->data['subjectnames'] =  $this->mark->get_subject_names_by_exam($exam_id, $class_id, $section_id);
 $this->layout->view('mark_sheet/marksall', $this->data);
    }




Model is:

PHP
public function get_subject_list_all($exam_id, $class_id, $section_id)
    {
        
        $this->db->select('M.*,S.name AS subject, G.point, G.name');
        $this->db->from('marks AS M');   
        $this->db->distinct('S.name');      
        $this->db->join('subjects AS S', 'S.id = M.subject_id', 'left');
        $this->db->join('grades AS G', 'G.id = M.grade_id', 'left');
        $this->db->where('M.academic_year_id', $this->academic_year_id);  
        
        $this->db->where('M.class_id', $class_id);
        $this->db->where('M.section_id', $section_id);
        $this->db->where('M.exam_id', $exam_id);
       
        return $this->db->get()->result();     
    }




My Output is:

Subject total		 obtain
sub1	100				80					
sub1	100				74					
sub2	150				125						
sub2	150				108					
sub3	75				45						
sub3	75				63



And I want the result like below:

Sub1			sub2			sub3
total	obtain	total	obtain	total	obtain
100		80		150		125		75		45
100		74		150		108		75		63


Please help I dont have any idea that how to do this?

What I have tried:

PHP
<table>
	<tr>
	<!--    <th rowspan="2"><?php //echo $this->lang->line('sl_no'); ?></th> -->
	<?php    if (isset($subjectnames) && !empty($subjectnames)) {
	foreach ($subjectnames as $sub) { ?>
	<th colspan="2"><?php echo $sub->subject . " Marks ".$sub->exam_total_mark; ?></th>
	<?php } } ?>   
	</tr>
		if (isset($subjects) && !empty($subjects)) {
		?>
		<tr>
		<?php 
			foreach ($subjectnames as $sub) { ?>   
			<td>
			<?php
				foreach ($subjects as $obj) {  
				?>
					<table>
					<?php while($obj->subject == $sub->subject) { ?>
					<tr>
					<td><?php echo $obj->exam_total_mark; ?></td>
					<td><?php echo $obj->obtain_total_mark; ?></td>                            
					</tr>
					<?php } ?>
					</table>
				<?php } ?>

			</td>
			<?php       } ?>
		</tr>
		<?php } ?>
	</table>
Posted
Updated 10-Mar-21 7:17am
v3

1 solution

It took some time but finally I managed to do it.

PHP
<?php    if (isset($subjectnames) && !empty($subjectnames)) {?>
                          <tr>
                        <?php  foreach ($subjectnames as $sub) { ?>
                          <th colspan="2"><?php echo $sub->subject; ?>
                          <table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                          <?php  foreach ($subjects as $obj) {
                            if($obj->subject == $sub->subject) { ?>
                              <tr>
                                  <td><?php echo $obj->exam_total_mark; ?></td>
                                  <td><?php echo $obj->obtain_total_mark; ?></td>
                              </tr>
                              <?php } } ?>
                              </table>
                          </th>
                          <?php }  ?>
                      </tr>
                    <?php } ?>
 
Share this answer
 

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