我有以下排名查询可以很好地工作,每页限制25条记录,它显示前25条记录的第1-25位,但是当我转到下一页时,排名应保持在第1-25位(应说第26位) -50
("SELECT image, name, wins, losses, level, xp, wins
AS W, losses AS L, TRUNCATE(wins/IF(wins=0,1,wins+losses)*100,0)
AS PCT, @curRank := @curRank + 1 AS rank FROM teams p,
(SELECT @curRank := 0) r WHERE `console` = 3 AND `game` = 23
AND `laddertype` = 1 ORDER BY xp
DESC LIMIT " . mysql_real_escape_string($limit) . ", 25");
//get page
$page = 0;
if (isset($_GET['id'])) {
$rank = mysql_query("SELECT image, name, wins, losses, level, xp, wins AS W, losses AS L, TRUNCATE(wins/IF(wins=0,1,wins+losses)*100,0) AS PCT, @curRank := @curRank + 1 AS rank FROM `teams` p, (SELECT @curRank := 0) r WHERE `console` = 3 AND `game` = 23 AND `laddertype` = 1 AND `id` = ".mysql_real_escape_string($_GET['id'])." LIMIT 1");
$rank = mysql_fetch_assoc($rank);
$rank = $rank['rank'];
$page = ceil($rank/25)-1;
}
if (isset($_GET['page'])) {
$page = (int)$_GET['page'];
}
$limit = $page * 25;
//do pagination
$teamcount = $teamtotal['COUNT(*)'];
if (isset($_GET['id'])) {
$urlstring = '//website.com/?id='.$_GET['id'];
}else{
$urlstring = '//website.com/';
}
$template['PAGINATION'] = getpages($urlstring, (ceil($teamcount / 25) - 1), $page);
我如何获得等级列随分页而变化?
最佳答案
我想通了,我需要为此设置(SELECT @curRank := 0)
而不是(SELECT @curRank := $limit)