How to count all records but only retrieve (LIMIT) a specific number for display?

后端 未结 4 1141
我在风中等你
我在风中等你 2021-01-13 12:29

I want to echo only the first 10 rows, but I need to count the total number of rows affected by the query.

I was doing a LIMIT 10 and then counting with

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-13 12:42

    It's pretty standard to issue two queries, one selecting the desired columns with the limit clause and another selecting only a count with no limit.

    For example

    $countQuery = 'SELECT COUNT(1) FROM Badges WHERE UID = ?';
    $limitQuery = 'SELECT * FROM Badges WHERE UID = ? ORDER BY `Date` DESC LIMIT 0, 10';
    

提交回复
热议问题