Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Why it can't paging?!

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry .. forgot to disable smiles...
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Andres Gonzalez !It works well!
 
Happily living in the valley of the dried frogs with a few tiny ads.
The trailboss has a kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic