PHP / MySQL - 内部加入排名

时间:2015-03-16 20:14:26

标签: php mysql join rank

我现在的询问:

SELECT * FROM posts as p
INNER JOIN users as u
ON p.author = u.uid
INNER JOIN usergroups as ug
ON u.usergroup = ug.gid
WHERE tid_parent = ?

例如,此查询将提供以下数据:

http://gyazo.com/e2ce3d53698fef66bc18a0ea9ce84756.png

我喜欢这些排名(使用 @curRank:= @curRank + 1 AS等级)。

1 个答案:

答案 0 :(得分:0)

当您循环输出表时,请保持计数并将计数值打印为等级

 $c=1;
 foreach($results as $result){
   //all the table row html
   echo $c;
   //all rest of table row html
   $c++;
  }