mysql 数据库分页逻辑

mysql 数据库分页逻辑

// 基于0,  返回0:错误, 否则返回总页数
uint get_recs_on_page_of(int page_index, int n_per_page)
{
     int n = select  count(*) from books;
     int page_count;
     page_count = n/page_count;
     n?(page_count += n%page_count?1:0): page_count=1;
    
     if ( page_index >= page_count ) return 0;
     int offset = page_index*n_per_page;
     print (select * from table where ... limit offset, n_per_page);
     return page_count;
}

你可能感兴趣的:(mysql)