This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why it can't paging?!

 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone:
I have a guestbook using mysql.I want to paging and each page have six record.But it remain the first page when I click the "next page"!But I have eighteen record in all.Why?My jsp code is:
////////////////////////////////////////main.jsp///////////////////////////////////////////////
........ ........... ........... ......... ........... .......... .......... ..........
<%
String sql="select * from statement where fatherid is null";
String sqlnum="select count(*) from statement";
ResultSet rs;
int numCount=0;
int pageSize=6;
int intpage=1;
String strPage="";
rs = lyo.executequery(sql);
while(rs.next()){
%>
<tr><%String sid=rs.getString("id");%>
<td><a href="/lyojsp/viewtitle.jsp?id=<%=sid%>"><%=rs.getString("title")%></a></td>
<td><%=rs.getString("content")%></td>
<td><%=rs.getString("name")%></td>
<td><%=rs.getString("time")%></td>
</tr>
<%
}
rs=lyo.executequery(sqlnum);

if(rs.next()){
numCount=rs.getInt(1);
if(intpage>numCount)
intpage=numCount;
}
int pageint=(numCount+pageSize-1)/pageSize;
if(intpage>numCount) intpage=pageint;
strPage=request.getParameter("id");
if (strPage==null){
intpage=1;}else{
intpage=Integer.parseInt(strPage);
if(intpage<1)
intpage=1;
}
%>
</table><h5>The Total is</h5><font color=red><%=numCount%></font><h5>record</h5><h4><%=pageint%></h4><h4>page</h4><p>
The<%=intpage%>page <%if(intpage<numCount){%><a href="/lyojsp/main.jsp?id=<%=intpage+1%>">next page</a><%}%>
<%if(intpage>1){%><a href="/lyojsp/main.jsp?id=<%=intpage-1%>">previous</a><%}%>
Why?Anyone want to help me?Thank you.
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you must be doing something wrong with your calculations. I usually do not do this manually (paging), since there are existings tools that allow you to do it very easily...
For instance, I use the pager taglib, which pretty much does the same as you're trying to do. You can set up how many records you want in every page very easy without doing "complex" calculations...Have you tried it...? I'm sure your code will be a lot cleaner and it'll save you lots of times
hope it helps
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andres Gonzalez :
I use it but it is difficult to control.And it don't work property.When I click the "next page" the page dosn't change.Why?
I had give the tag the parameter And it have pageurl,pagenumber.
[ April 27, 2003: Message edited by: lyo lyo ]
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not difficult to control once you've configured properly . you must be missing something
quick example:

this is just a quick and dirty example... have a look at the documentation, they explained all this step by step
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry .. forgot to disable smiles...
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Andres Gonzalez !It works well!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic