Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

if else on row-based calculation

$
0
0

Hi,

 

I'm trying to develop an online merit award system for our school at the moment.

 

I've got a table that notes the different types of awards that students can get, in various columns, with the last column providing a total points.  Some awards are worth different points, which is why $total is calculated as:

$total['total']  = $row_recipients['pb4l'] + $row_recipients['pb4l'] + $row_recipients['sports_award'] + $row_recipients['offline_sports_award'] + (5 *  $row_recipients['welfare_award']) + (5 *  $row_recipients['offline_welfare_award']) + (10 *  $row_recipients['senior_executive_award']) + (10 *  $row_recipients['offline_senior_executive_award'])  ;

That works fine, and I've calculated each student's total accurately. The next part is what I'm struggling with.  Students attain certain levels ($level) based on their total 50 - Bronze, 100 - Silver, 150 - Gold etc.

 

The code for calculating this is:

 


if ($total >= 50 && $total< 100)
{
$level = "Bronze";	
}

if ($total >= 100 && $total< 150)
{
$level = "Silver";	
}

if ($total>= 150 && $total< 200)
{
$level = "Gold";	
}

if ($total >= 200 && $total < 350)
{
$level = "School Trophy";	
}

if ($total >= 350 && $total< 500)
{
$level = "Platinum";	
}

if ($total >= 500)
{
$level = "Diamond";	
}


echo $level ;

The level is accurate for the first few rows displayed, where $total has a value greater than 0. But for rows below that, where students have been given no awards, The $level value is the same as the last row with a $total value greater than 0.

 

Please tell me where I'm going wrong.

 

Cheers,

Dave


Viewing all articles
Browse latest Browse all 13200

Trending Articles