开发者

Classify exam grades into leagues

开发者 https://www.devze.com 2023-02-23 00:37 出处:网络
Hey guys I want to make an academic-oriented matching website that allows boys and girls to find their potential partners through academic performance and hobbies.

Hey guys I want to make an academic-oriented matching website that allows boys and girls to find their potential partners through academic performance and hobbies.

I was just thinking about convert quantity of exam grades eg. A, B, C and convert them into leagues like S-class, A-class. First I want to convert exam grade A into integer of 5, exam grade B into integer of 4 and so on. Then I sum them up and classify them into their respective classes.

The original and tiring code... I'm not sure whether it's going to work.

$obtaindata = mysql_fetch_assoc(mysql_query('SELECT * FROM userinfo WHERE primaryemel="' . $_COOKIE['smkdtuser'] . '"'));

$pmrresults = json_decode($obtaindata['pmr']);
$spmresults = json_decode($obtaindata['spm']);
$upsresults = json_decode($obtaindata['upsr']);

function calculateClassForPMR ($pmrresults) {
$aquality = (int)$pmrresults['a'] * 5;
$bqua开发者_开发百科lity = (int)$pmrresults['b'] * 4;
$cquality = (int)$pmrresults['c'] * 3;
$dquality = (int)$pmrresults['d'] * 2;
$gquality = (int)$pmrresults['g'] * 1;

$additup = $aquality + $bquality + $cquality + $dquality + $gquality;

//Classify sum of scores to their respective class
if ($additup => 35) {$classified = "s";}
elseif ($additup >= 29 && $additup <= 34) {$classified = "a";}
elseif ($additup >= 23 && $additup <= 28) {$classified = "b";}
elseif ($additup >= 17 && $additup <= 22) {$classified = "c";}
elseif ($additup >= 11 && $additup <= 16) {$classified = "d";}
elseif ($additup >= 0 && $additup <= 10) {$classified = "e";}
else {$classified = "wtf";};

return $classified; }

Don't blame me though ,I was just started learning php and try to do something weird...

Any replies or comments are highly appreciated.


when using json_decode i assume that you have {"a":1,"b":2,"c":3,"d":4,"e":5} something like this containt in that tabel row. Try to use :

$pmrresults = var_dump(json_decode($obtaindata['pmr'], true)) then you can use $pmrresults['a'];

You have to json_encode() when you store values to DB

I don't want to rent another server just to test it... it's costly. ... user XAMPP it's free for testing.

0

精彩评论

暂无评论...
验证码 换一张
取 消