将考试成绩分为等级
大家好,我想制作一个以学术为导向的匹配网站,让男孩和女孩通过学习成绩和兴趣爱好找到潜在的伴侣。
我只是在考虑转换考试成绩的数量,例如。 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 并尝试做一些奇怪的事情......
任何回复或评论都非常感谢。
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;
$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; }
Don't blame me though ,I was just started learning php and try to do something weird...
Any replies or comments are highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 json_decode 时,我假设您有
{"a":1,"b":2,"c":3,"d":4,"e":5}
类似这样的内容在该表格行中。尝试使用:$pmrresults = var_dump(json_decode($obtaindata['pmr'], true))
然后你可以使用$pmrresults['a'];
你有当您将值存储到数据库时,使用
json_encode()
我不想租另一台服务器只是为了测试它......它的成本很高。
...用户 XAMPP 它是免费的用于测试。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 DBI don't want to rent another server just to test it... it's costly.
... user XAMPP it's free for testing.