I’m running a query to have two columns in an html table.
c.course_unit
m.score
In the m.score column, i want to do an if statement so that a point is awarded according to a certain range of the score. e.g
if ($row['m.score'] >= 70) {
point = 5;
}
Then use each point awarded for each row multiplied with it’s corresponding values in the other column i.e (c.course_unit).
This is what i’ve been able to come up with so far, and IT’S NOT EVEN CLOSE TO IT.
I’ll most appreciate you sincere help.
Thank you.
$grade_point = 0 ;
while ($row =mysql_fetch_assoc($query)) {
foreach ($row as $value) {
if ($value >= 70) {
$value['m.score'] = 5;
}
if ( $value['m.score'] >= 60 && $value['m.score']<= 69 ) {
$value['m.score'] = 4;
}
if ( $value['m.score'] >= 50 && $value['m.score']<= 59 ) {
$value['m.score'] = 3;
}
if ( $value['m.score'] >= 45 && $value['m.score']<= 49 ) {
$value['m.score'] = 2;
}
if ( $value['m.score'] >=40 && $value['m.score']<= 45 ) {
$value['m.score'] = 1;
}
if ($value['m.score'] < 40) {
$value['m.score'] = 0;
}
$grade_point += $value['m.score'] * $value['c.course_unit'];
echo "$grade_point";
}
}
Just remove the foreach loop. Its iterating through your fields.
Here is the complete code that should work. I also change some variable name to fix it.
Note.
elseifcode can be reduced. (Thanks to zerkms)