Mysql一条语句查询分页的列表以及总数

// 获取列表
$get_sql = "SELECT
                SQL_CALC_FOUND_ROWS field1,field2
            FROM
                table
            WHERE
                name ='1'
            ORDER BY
                add_time desc
            LIMIT 2,20
";
// 获取总数(不是当前列表的总数)
$get_total_sql = "SELECT FOUND_ROWS() as total";

类似文章