MCPcopy Index your code
hub / github.com/TruthHun/BookStack / GetPagesInfo

Function GetPagesInfo

utils/pager.go:37–59  ·  view source on GitHub ↗

** * 分页函数,适用任何表 * 返回 总记录条数,总页数,以及当前请求的数据RawSeter,调用中需要"rs.QueryRows(&tblog)"就行了 --tblog是一个Tb_log对象 * 参数:表名,当前页数,页面大小,条件(查询条件,格式为 " and name='zhifeiya' and age=12 ") */

(tableName string, currentpage int, pagesize int, conditions string)

Source from the content-addressed store, hash-verified

35 * 参数:表名,当前页数,页面大小,条件(查询条件,格式为 " and name='zhifeiya' and age=12 "
36 */
37func GetPagesInfo(tableName string, currentpage int, pagesize int, conditions string) (int, int, orm.RawSeter) {
38 if currentpage <= 1 {
39 currentpage = 1
40 }
41 if pagesize == 0 {
42 pagesize = 20
43 }
44 var rs orm.RawSeter
45 o := orm.NewOrm()
46 var totalItem, totalpages int = 0, 0 //总条数,总页数
47 o.Raw("SELECT count(*) FROM " + tableName + " where 1 > 0 " + conditions).QueryRow(&totalItem) //获取总条数
48 if totalItem <= pagesize {
49 totalpages = 1
50 } else if totalItem > pagesize {
51 temp := totalItem / pagesize
52 if (totalItem % pagesize) != 0 {
53 temp = temp + 1
54 }
55 totalpages = temp
56 }
57 rs = o.Raw("select * from " + tableName + " where 1 > 0 " + conditions + " LIMIT " + con.Itoa((currentpage-1)*pagesize) + "," + con.Itoa(pagesize))
58 return totalItem, totalpages, rs
59}
60
61/**
62* 返回总记录条数,总页数,当前页面数据,分页html

Callers 1

GetPagerLinksFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected