嘿伙计们,我想建立一个以学术为导向的配对网站,让男孩和女孩通过学业表现和爱好找到他们的潜在合作伙伴。
我只是考虑转换考试成绩的数量,例如。 A,B,C并将它们转换为S级,A级等联赛。首先,我想将考试成绩A转换为5的整数,将考试成绩B转换为4的整数,依此类推。然后我将它们总结并将它们分类到各自的类中。
原始和疲惫的代码......我不确定它是否会起作用。
$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;
$bquality = (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; }
不要怪我,我刚开始学习php并尝试做一些奇怪的事情......
非常感谢任何回复或评论。
答案 0 :(得分:0)
当使用json_decode时,我假设你在该tabel行中有{"a":1,"b":2,"c":3,"d":4,"e":5}
这样的东西。尝试使用:
$pmrresults = var_dump(json_decode($obtaindata['pmr'], true))
然后您可以使用$pmrresults['a'];
将值存储到DB
时,您必须json_encode()
I don't want to rent another server just to test it... it's costly.
...用户XAMPP可免费测试。