download12749 2017-09-24 04:42
浏览 40

Web开发-SQL创建最近的页面

I'm creating a web application where one of the features will include getting the recent games played. I want to make it so the 25 most recent games played will be on the first page, with a page selection at the bottom. (Games data will be grabbed from MYSQL)

I understand this is a concept many sites already have, but after extensive googling I'm uncertain of a way to efficiently do this. The only thing I can currently think of is querying every game of theirs then splitting it into pages, but wouldn't that become extremely inefficient when it gets in the thousands?

Any help, or link to outside sources that explain this topic would be greatly appreciated, thank you!

  • 写回答

1条回答 默认 最新

  • dongzuo4666 2017-09-24 04:49
    关注

    For pagination use limit:

    The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement.

    ... the first argument specifies the [zero origin] offset of the first row to return, and the second specifies the maximum number of rows to return. ...

    SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15

    So for the first page it's enough to request all games played, order by time_played DESCending, limit 25. Just be sure to put an index on the time_played column.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度