PHP数组逻辑

时间:2013-07-26 23:27:44

标签: php mysql

如何设置一个包含布尔值或测试分数的主题数组?

如果有人在某个科目的每次考试中取得高分,我都会尝试展示金牌。

我希望我能够更清楚地解决这个问题,但这里有一些代码可以帮助解释:

$resTestsQryStr = "SELECT TestID, Subject FROM Tests
                            WHERE " . $edstr . " AND " . $plstr . " AND " . $levelStr . " GROUP BY Subject";
$resTests = mysql_query($resTestsQryStr);

while ($rowT=mysql_fetch_array($resTests))
{
    $subject=$rowT['Subject'];    
    $tID=$rowT['TestID'];
    $resScore= mysql_query("SELECT Score FROM CompletedTests WHERE UserNum = '$userNum' AND TestID = '$tID'");
    $rowScore= mysql_fetch_array($resScore);      
        if ($rowScore['Score'] < 100){
            $medalWinArray[$subject]= false;
            break;
        }
        else    
            $medalWinArray[$subject]= true;
}

1 个答案:

答案 0 :(得分:0)

我认为应该这样做:

SELECT Subject, MIN(Score) >= 100 GoldMedal
FROM Tests t
JOIN Completed Tests c ON c.TestID = t.TestID
WHERE $edstr AND $plstr AND $level
AND c.userNum = '$userNum'
GROUP BY Subject