我在数据库中有表包含玩家点数。我有页面index.php显示该表:
if (isset($_GET['page'])){
$pageload=intval($_GET['page']);
if ($pageload==1 || $pageload==""){
$Lpage=0;
}
else {
$Lpage=($pageload*10)-10;
}}
else{$Lpage=0;}
$expects="
SELECT id
, user_id
, sum(points) AS points
FROM expectation
GROUP
BY user_id
ORDER
BY points DESC
Limit $Lpage,10
";
$result_ex=mysqli_query($berikane,$expects);
$row_ex=mysqli_fetch_assoc($result_ex);
do{
$xx=$xx+1;
?>
<tr>
<td width="40" height="35" align="center"><?php echo $xx?></td>
<td width="170" height="35"><?php
echo $row_puid['username'];
?></td>
<td height="35" align="center"><a href="Details.php?<?php echo "uid=".$puid ?>"><?php echo $row_ex['points']?></a></td>
</tr>
<?php }while ($row_ex = mysqli_fetch_assoc($result_ex));
$expects2="SELECT id,user_id,sum(points) AS points FROM expectation GROUP BY user_id ORDER BY points DESC ";
$result_ex2=mysqli_query($berikane,$expects2);
$row_ex2=mysqli_fetch_assoc($result_ex2);
$pcount=mysqli_num_rows($result_ex2);
$pcount=$pcount/10;
$pcount=ceil($pcount);
?>
<tr>
<td height="35" colspan="3" align="center"><?php
for ($pg=1;$pg<=$pcount;$pg++){
?> <a href="index.php?page=<?php echo $pg ?>" style="text-decoration:none; font-size:18px"><?php echo $pg ?> </a><?php
}
?>
现在index.php从表中显示10行,我必须点击页面的数量才能转到该页面(1,2,3,..等)我想帮助用户点击按钮然后会去到包含他的排名的表中的那个页面。 我怎么能这样做?
答案 0 :(得分:0)
获取页码
获取当前用户点
计算所有分数超过当前用户点的记录
除以每页上的记录数量
现在你应该得到页码
答案 1 :(得分:0)
我通过添加这个来解决它:
do{
$z=$z+1;
if($row_ex2['user_id']==$row['user_id']){
$showpage=$z;
$showpage=ceil($showpage/10);
}}while ($row_ex2 = mysqli_fetch_assoc($result_ex2))
<a href="index.php?page=<?php echo $showpage ?>">show my rank</a>