【发布时间】:2015-10-11 15:56:10
【问题描述】:
我有问题。我正在根据申请人的考试成绩制定排名系统。代码如下:
$testScore = "SELECT Overall_Score, First_Name
FROM applicant_details, person, person_details
where person.ID_No like person_details.ID_No and Position_Applied = 'Work137' and Person_Type = 'Applicant' and applicant_details.ID_No like person.ID_No";
$result = mysql_query($testScore);
$rank = 0;
$lastScore = false;
$rows = 0;
while( $row = mysql_fetch_array( $result ) ){
$name = $row['First_Name'];
$overall = $row['Overall_Score'];
$rows++;
if( $lastScore != $overall){
$lastScore = $overall;
$rank = $rows;
}
echo"Name:$name rank:$rank score: $overall </br>";
}
此代码的输出是第一个被查询的人是数字1。示例输出:
姓名:犹他州排名:1 得分:85
姓名:立夏等级:2 得分:90
我想要一个输出:
姓名:犹他州排名:2 得分:85
姓名:立夏等级1得分:90
【问题讨论】:
-
修复您的查询以使用正确的
join语法并在表之间使用正确的连接条件。