Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jsp page numbering

Status
Not open for further replies.

sensory21

Programmer
Jan 27, 2004
79
GB
Hi , I need help with this, the code compile ok and display what I want for the first page, once you click on the link Next it says thispage=2 which is good but don't initialise thispage=2, so I know my mistake it's because I initialise thispage=0; at the start but if I don't the program doesn't compile at the point when it says:
prev_page = thispage-1;
which I don't understand as I initialise
thispage=1; on the line just before; what it is that I don't grasp?
I've also tried to replace some int values by boolean but I haven't been able to make it work!



/* page number links */

int per_page=2; //change the number of records per page
int thispage=0;
int prev_page;
int next_page;
int page_start;
int num_pages;
if (ResultCount >= 1){

if (thispage == 0) thispage = 1;
prev_page = thispage-1;
next_page = thispage+1;

}else{
thispage = 1;
prev_page = 1;
next_page = 1;
}

page_start = (per_page * thispage) - per_page;
if (ResultCount <= per_page){
num_pages = 1;
}else{
if ((ResultCount % per_page) == 0){
num_pages = (ResultCount / per_page);
}else{
num_pages = (ResultCount / per_page) + 1;
}
}

num_pages = (int) num_pages;
if ((thispage > num_pages) || (thispage < 0)) out.println(&quot;You have specified an invalid page number&quot;);
PreparedStatement prep = Co.prepareStatement(&quot;SELECT company_name, contact_name, address, address2, city, pcode, country, phone, fax, email, website FROM customer order by company_name LIMIT ?, ? &quot;);
for (int j=1; j<2; j++) {
prep.setInt(1,page_start);
prep.setInt(2,per_page);

}//end for

if (ResultCount > 0){
if (prev_page > 0) out.println(&quot;<font size=\&quot;3\&quot;><a href=\&quot;customer.jsp?thispage=&quot; + prev_page + &quot;\&quot;><b>Previous</b></a></font>&quot;);
}//end if


for (int i = 1; i <= num_pages; i++) {
if (i != thispage) {
out.println(&quot; <font color=\&quot;red\&quot; size=\&quot;2\&quot;><a href=\&quot;customer.jsp?thispage=&quot; + i + &quot;\&quot;>&quot; + i + &quot;</a></font>&quot;);

}else{
if (ResultCount > per_page) out.println(&quot; <font color=\&quot;green\&quot; size=\&quot;+1\&quot;>&quot; + i + &quot;</font>&quot;);
//thispage is different from i
}//end else
}//end for

if (thispage != num_pages){
out.println(&quot;<font size=\&quot;3\&quot;><a href=\&quot;customer.jsp?thispage=&quot; + next_page + &quot;\&quot;><b>Next</b></a></font>&quot;);
}


Cheers
Vero
 
Hi,

I hope this will help you...

thread695-754786

Cheers,
Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top