菜鸟写的代码,求简化

浏览:199 发布日期:2019/06/12 分类:求助交流
<?php

$sqla = "SELECT a1,a2,a3,a4,a5 FROM sai_match WHERE id = 1 and ab = 'a'";//获取id为1的组别的a队员5个项目分数
$result = mysql_query($sqla);
$arr = mysql_fetch_assoc($result);
$counta = $arr[a1]+$arr[a2]+$arr[a3]+$arr[a4]+$arr[a5];
$sqlb = "SELECT a1,a2,a3,a4,a5 FROM sai_match WHERE id = 1 and ab = 'b'";//获取id为1的组别的b队员5个项目分数
$result = mysql_query($sqlb);
$arr = mysql_fetch_assoc($result);
$countb = $arr[a1]+$arr[a2]+$arr[a3]+$arr[a4]+$arr[a5];
$sqlc = "SELECT a1,a2,a3,a4,a5 FROM sai_match WHERE id = 1 and ab = 'c'";//获取id为1的组别的c队员5个项目分数
$result = mysql_query($sqlc);
$arr = mysql_fetch_assoc($result);
$countc = $arr[a1]+$arr[a2]+$arr[a3]+$arr[a4]+$arr[a5];
$sqld = "SELECT a1,a2,a3,a4,a5 FROM sai_match WHERE id = 1 and ab = 'd'";//获取id为1的组别的d队员5个项目分数
$result = mysql_query($sqld);
$arr = mysql_fetch_assoc($result);
$countd = $arr[a1]+$arr[a2]+$arr[a3]+$arr[a4]+$arr[a5];

$count = $counta+$countb+$countc+$countd; //将5个队员成绩求和,得出本组总分.

echo $count;
?>

请帮忙把这段代码 优化一下,菜鸟求助.
最佳答案
评论( 相关
后面还有条评论,点击查看>>