Getting Subject Position of a student from total scores using PHP

62 Views Asked by At

I am working on a project that gets subject average, subject position and class position of a student in a class.

My challenge now is how to get Subject Position and class position of a student in a class.

This is my Table arrangement:

table name=academic_result

REG | class | session | term | subject | total
01  | js1   |200/2001 | 1T   | csc101  | 85
02  | js1   |200/2001 | 1T   | csc101  | 90
01  | js1   |200/2001 | 1T   | bus101  | 70
02  | js1   |200/2001 | 1T   | bus101  | 90
01  | js1   |200/2001 | 1T   | chem101 | 75
02  | js1   |200/2001 | 1T   | chem101 | 85
<?php
                      
// Subject Ranking
$stmt = $link->prepare("SELECT REG, term, subject, session, total, dense_rank() OVER( partition by subject ORDER BY total desc ) 
AS 'dense_rank' FROM academic_result WHERE class=? AND term=? AND session=?");
$stmt->bind_param("sss", $class, $term, $session);
$stmt->execute();
$checkSubject = $stmt->get_result();

$result_SUBPO = $checkSubject->fetch_assoc();
echo ordinal($result_SUBPO['dense_rank']);
?>
Subject | Total | Subject ranking | class position 
csc101  | 85    |1st              |
bus101  | 70    |1st              | 
chem101 | 75    |1st              |  

this what the query out put looks like, this is the result of a student with Reg No(01). Subject ranking(subject position) for a student is always 1st, this is where am having problem. The subject ranking (subject position) is alto vary depending on their subject total score.

I still want to get Class position of a student from the table.

0

There are 0 best solutions below