davidcriniti Posted September 18, 2013 Share Posted September 18, 2013 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 Link to comment https://forums.phpfreaks.com/topic/282266-if-else-on-row-based-calculation/ Share on other sites More sharing options...
davidcriniti Posted September 19, 2013 Author Share Posted September 19, 2013 Sorry. Simple error. Forgot to account for scenario with points less than the first level. if ($total < 50) { $level= ""; } Link to comment https://forums.phpfreaks.com/topic/282266-if-else-on-row-based-calculation/#findComment-1450178 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.