ITeye博客

mysql 数据库分页逻辑

monkeycn · 2011-05-20 09:19 · 数据库 · Markdown

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;

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。