如何得到某条记录的排名?
admin 发表于 2010-07-22 | 来源:互联网 | 阅读:
想知道某条记录的排名,如何实现?
架设我有 order by hits desc,我想知道其中id为123的记录已hits排名时排第几?经常用于歌手名次或专辑名次。
想知道某条记录的排名,如何实现?
架设我有 order by hits desc,我想知道其中id为123的记录已hits排名时排第几?经常用于歌手名次或专辑名次。
评论功能因故关闭!
请加入我们的QQ群一起参与讨论:群号59400482(500人超级群)
取到的记录不是到数组里面了吗?然后。。。
用数组的索引+1
这个很好做的,在while循环的时候设置一个$i;$i=1 while循环完后$i++ 这样所有的排名都会有的。
在SQL里用正常查询语句,例如select count(*) from table where id>10获得count(*)数,应该就是你说的排名了吧如果不是int索引来查找的话,可能就麻烦了
路过,帮顶下
4樓 正解
支持4楼
[code=SQL] select count(*)+1 from biao where hits> (select hits from biao where id=123) [/code]
SQL code
select count(*)+1 from biao where hits> (select hits from biao where
id=123)