2014-11-24 68 views
0

我有以下排名查詢工作正常,每頁25條記錄的限制,它顯示前25條記錄的第1-25條,但是當我進入下一頁時,排名停留同樣的第1場 - 第25場,應該說是第26場 - 第50場。如何分頁MySql排名查詢

("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); 

我該如何獲得排名欄以改變分頁?

+0

修改起始值爲您的排名計算相應的...? – CBroe 2014-11-24 09:20:48

回答

1

我想通了,我需要設置(SELECT @curRank := 0)這不是(SELECT @curRank := $limit)