您的位置:首页 > 数据库

数据库分页程序解读

2014-01-08 13:25 204 查看
下面这段代码,初看上去,会是0,1循环

if (iPageNo == 0) {
iPageNo = 0;
} else {
System.out.println("before * 10,iPageNo is "+iPageNo);
iPageNo = Math.abs((iPageNo - 1) * iShowRows);

}
System.out.println("at the beginning of the page,iPage is "+iPageNo);


其实不然,看输出:

at the beginning of the page,iPage is 0

before click link

iPageNo=0

before * 10,iPageNo is 2

at the beginning of the page,iPage is 10

before click link

iPageNo=10

iPageNo就不过1,上来就是2.

for (i = ((cPage * iTotalSearchRecords) - (iTotalSearchRecords - 1)); i <= (cPage * iTotalSearchRecords); i++) {
System.out.println("i inside the for but before the if "+i);
if (i == ((iPageNo / iShowRows) + 1)) {
System.out.println("i inside the for loop and if condition is true "+i);


启动程序时,这一段的输出:

at the beginning of the page,iPage is 0

i inside the for but before the if 1

i inside the for loop and if condition is true 1

i inside the for but before the if 2

i inside the for but before the if 3

before click link

iPageNo=0

//// index of pages

int i = 0;
int cPage = 0;
if (iTotalRows != 0) {
cPage = ((int) (Math.ceil((double) iEndResultNo
/ (iTotalSearchRecords * iShowRows))));
System.out.println("iEndResultNo "+iEndResultNo);
System.out.println("iTotalSearchRecords*iEndResultNo "+iTotalSearchRecords*iEndResultNo);
System.out.println("cPage "+cPage);


输出:

iEndResultNo 10

iTotalSearchRecords*iEndResultNo 30

cPage 1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: