java - 如何解决按登录时间分页加载数据会有重复的问题?
PHP中文网
PHP中文网 2017-04-17 13:25:20
0
2
908

场景是这样的:安卓客户端要按登录时间在首页显示用户列表,服务端提供数据,每次下拉请求,相当于是从服务端请求加载下一页的的数据,但是这样会有一个问题,假如第一页服务端给了客户端最新的数据,但是在加载第二页之前,又有几个新的用户登录了进来,这样这些新用户就是最新登录的,所以在第二页的时候就会有一些第一页的用户,请教给位大神怎么解决这个问题?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
小葫芦

Several options:

  1. Client-side deduplication, advantage: simple to implement. Disadvantages: Data is inaccurate.

  2. (Recommended) Sort by time. When the client obtains the next page of data, it returns the login time of the last data. When querying the database, select * from table where login time < the last data Login time order by login time.

  3. Record a timestamp for each client. Update this timestamp when getting the first page. When querying the next page, select * from table where login time < timestamp order by login time limit current Page

左手右手慢动作

If the order of users remains unchanged, you can record the last user displayed each time. After getting the next page from the server, search first. If there is the last user before, skip him and the previous users. , in order to avoid not having enough users, you may need to load a few more at a time according to the actual situation. If a user who was supposed to be on the second page moves to the front because he logged in again, that should be fine, and generally no one will notice.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!