如何在PHP MYSQL中统计用户前后的特定用户
I have a pre-register form. After signup I have to show the current registerar his current position. The current position is determined by counting rows ahead and behind of particular row.
For example, if the signup ID of Jack Smith is 42 I want to show how many user are ahead of him registered and behind him. If the total record is supposed to have 200 enteries.
I am wondering how I can achieve this in MYSQL and PHP.
Thanks in advance!
我有一个预注册表格。 注册后,我必须向当前的注册商展示他当前的位置。 当前位置是通过计算特定行前后的行来确定的。 p>
例如,如果Jack Smith的注册ID为42,我想显示有多少用户在他注册之前 在他身后。 如果总记录应该有200个进入。 p>
我想知道如何在MYSQL和PHP中实现这一点。 p>
提前致谢! p> div>
You need to count the number of id lower than your current user's id and the number of id higher :
SELECT COUNT(ID) FROM my_table WHERE ID < 42;
SELECT COUNT(ID) FROM my_table WHERE ID > 42;
Hope this helps.