如何在同一个表中对同一用户的多行进行排名

时间:2013-12-03 21:24:10

标签: php pdo ranking

我正在尝试编写一个用户有多个字符的代码,用户可以根据角色的级别看到他们的角色排名。 这些字符都在同一个表格中,表格的设置基本上是:

ID-或CharacterId-CharacterName-CharacterLevel

以下代码的问题是它给我一个语法错误,意外的'1'(T_DNUMBER)

下面是PDO中的代码:(事先感谢任何帮助):

<?php    

if(isset($_POST['submit']))
{


$q = $conn->prepare("SELECT `charactername` FROM `users` WHERE id = :id ORDER BY
`characterlevel` DESC");
$q ->bindParam(':id', $sessionid , PDO::PARAM_INT);
$q->execute();

$rank = 0;
$last_score = false;
$rows = 0;

while ($row = $q->fetch(PDO::FETCH_ASSOC)) 
$rows++;
if( $last_score!= $row['point'] ){
$last_score = $row['point'];
$rank = $rows;
}echo "rank ".$rank." is ".$row['charactername']." with the age of ".$row['age'].";
}
?>
<br />
<form action="1.php" method="POST">
<input type = "submit" name="submit" value= "submit"
</form>

1 个答案:

答案 0 :(得分:0)

不平衡"

echo "rank ".$rank." is ".$row[snip]." with the age of ".$row['age'].";
     ^-1---^       ^-2--^            ^--------3--------^             ^---?