Getting row before and after a query

前端 未结 5 2028
失恋的感觉
失恋的感觉 2021-01-16 20:15

I currently have this query

SELECT  short_url,
        type,
        file_thumbnail,
        file_embed,
        media.id,
        user,
        media.file_u         


        
5条回答
  •  无人及你
    2021-01-16 20:55

    Here's a couple key points your app should try to maintain:

    • Don't load more data than necessary. (You don't know if the user will use the prev/next rows or not.)
    • Make URLs sane, using stable URLs wherever possible. (The URL should not indicate that you want to be 3 next from row #127.)

    Keeping those goals in mind, I'd recommend that on clicking the "next row" link, the page pulls the next row's ID, then redirects to the permalink for that row. So, for example:

    http://example.com/media/1337/prev should run:

    SELECT id FROM media WHERE media.id < 1337 ORDER BY media.id DESC LIMIT 1
    

    And redirect to, presumably, http://example.com/media/1336.

    http://example.com/media/1337/next should run:

    SELECT id FROM media WHERE media.id > 1337 ORDER BY media.id ASC LIMIT 1
    

    And redirect to, presumably, http://example.com/media/1338.

提交回复
热议问题