Get total number of rows when using LIMIT

前端 未结 2 1007
旧巷少年郎
旧巷少年郎 2021-02-14 20:03

Been following examples from here and many other sites but not getting the expected results

Snippet of my PHP code;

$query=\"SELECT * FROM book\";
$resul         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-14 20:47

    Add a SQL_CALC_FOUND_ROWS to your select statement: http://dev.mysql.com/doc/refman/5.5/en/information-functions.html#function_found-rows

    This forces MySQL to count the rows as if the limit statement is not present.

    $query="SELECT SQL_CALC_FOUND_ROWS * FROM book LIMIT 0,4";
    

提交回复
热议问题