Solved

display search results in multiple pages, very urgent (not too difficult)

Posted on 2004-09-21
9
327 Views
Last Modified: 2010-04-01
Hi all, When displaying searched for items I am displaying them in a html table. Id like the search to span into a new page when the amount of items exceeds ten and another page if it exceeds twenty etc etc. Something like how google displays multiple pages for search results. How is this possible?
Thanks.
0
Comment
Question by:SuAeE
  • 2
  • 2
  • 2
  • +1
9 Comments
 
LVL 6

Expert Comment

by:CodingExperts
ID: 12110479
See if this is of any help....
http://www.codeproject.com/useritems/DBGrid.asp
0
 

Author Comment

by:SuAeE
ID: 12110497

Btw, Im using a mysql database.
0
 
LVL 6

Expert Comment

by:CodingExperts
ID: 12110520
> Im using a mysql database.
Should not be a problem. You can specify the appropriate JDBC driver for MySql in the code.

CodingExpert
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 21

Accepted Solution

by:
MogalManic earned 175 total points
ID: 12110647
Just store your query results on the session.  Are you doing the SQL querying within the JSP or are you using a Servlet?

If yours is just a simple application and it is the former then you could do something like this:

PagedQuery.jsp:

< jsp:useBean id="results" "scope="session" class="java.util.List"/>
< jsp:useBean id="pageNum" "scope="session" class="java.lang.Integer"/>
<% if (request.getMethod().equalsIgnoreCase("GET")) {%>
   <jsp:include page="query.jsp"/>
<%}%>
<form name='pagedForm' action='' method='post'/>

<table>
  <%
int rowIdx;
for(rowIdx=pageNum*MAX_ROWS_PER_PAGE;
     rowIdx<results.size() && (rowIdx<(pageNum+1)*MAX_ROWS_PER_PAGE;rowIdx++) {
   ResultsBean eachRow= (ResultsBean)resultsIT.next();
     %><tr><%
     // ... code to display the results
     %></tr><%
}
  %>
<% if (results.size()>MAX_ROWS_PER_PAGE) {%>
<table summary="next_prev Buttons">
  <tr>
      <td>
           <%if ((rowIdx-MAX_ROWS_PER_PAGE)>0) {%>
                   <input type='button' name='Page' value='Prev Page'/>
           <%}%>
      </td>
      <td>
           <%if (rowIdx<size()) {%>
                   <input type='button' name='Page' value='Next Page'/>
           <%}%>
      </td>
  </tr>
</table>
</table>
</form>


query.jsp:
< jsp:useBean id="results" "scope="session" class="java.util.List"/>
<%
//Java code to query DB and move results into 'results' list
...
*>
0
 

Author Comment

by:SuAeE
ID: 12110651

I had a look at that and to be honest it seems too complicated for me :( . And I really cant stand sifting through large amounts of code, much rather write it myself. Any other ideas?
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 175 total points
ID: 12110758
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12110781
You could also query the database on each page.  Increment/Decrement the pageNumber and post it on the request and when the query is executed, skip the results up until the page requested:
int recNo=0;
while(pageNo*RESULTS_PER_PAGE<recNo) {
   rs.next();  //Skip results in ResultSet before requested page
}

Then process the results up to RESULTS_PER_PAGE.

The pageNumber could be incremented/decremented in a link like this:
<a href="pagedQuery.jsp?pageNo=<%=pageNo+1%>">Next Page</a>
<a href="pagedQuery.jsp?pageNo=<%=pageNo-1%>">Previous Page</a>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The business world is becoming increasingly integrated with tech. It’s not just for a select few anymore — but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and it’s likely…
Most MSPs worth their salt are already offering cybersecurity to their customers. But cybersecurity as a service is wide encompassing and can mean many things.  So where are MSPs falling in this spectrum?
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question