转到我在表中的排名

时间:2018-05-03 17:55:42

标签: php mysql html-table ranking

我在数据库中有表包含玩家点数。我有页面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 ?>&nbsp;&nbsp; </a><?php 
            }     
   ?>

现在index.php从表中显示10行,我必须点击页面的数量才能转到该页面(1,2,3,..等)我想帮助用户点击按钮然后会去到包含他的排名的表中的那个页面。 我怎么能这样做?

2 个答案:

答案 0 :(得分:0)

获取页码

  1. 获取当前用户点

  2. 计算所有分数超过当前用户点的记录

  3. 除以每页上的记录数量

  4. 现在你应该得到页码

答案 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>