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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

split up search results

Status
Not open for further replies.

tyutghf

Technical User
Apr 12, 2008
258
GB
I am using paging to display 10 search results at a time and at the foot of the page is the big list of available pages. This was fine whilst the database was small but it is growing quickly and there are now 60 pages, so having 1 2 3 4 5 6 7 8 9 10 11 12 13 14 etc etc all the way up to 60 is taking lots of room.

SO, I have been trying to do it in a similar way to google so say I am on the 30th page, instead of it listing all pages 1-60 it will show just 10 either side i.e.

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

I think I have stared at this for too long as I am messing it up [dazed]

Could someone have a quick look for me please?

Code:
<%
pagelist = 0
pagelistcounter = 0
do until pagelist > allrecords  
pagelistcounter = pagelistcounter + 1

'highlight page currently on
										if cstr(pagelist) = request.querystring("offset") then
										response.write "| <a href='?offset="&pagelist&"' class='currentpage'>"&pagelistcounter&"</a> "
										else

response.write "| <a href='?offset="&pagelist&"'>"&pagelistcounter&"</a> "
										end if

pagelist = pagelist + recordsonpage

loop
%>

So the above will loop through and display all pages but I want to just show 10 either side of request.querystring("offset")

Thanks
 
I guess that I think of things differently..... try something along these lines:

(NOTE: This is off of the top of my head... it's not meant to be a drag-and-drop answer, more of a guide)

Code:
iFirstPage = 1
iLastPage = allrecords
iCurrentPage = Request.QueryString("offset")

' First, see if you are at the beginning

If iCurrentPage < 20 Then
  ' We are towards the beginning...
  For i = 1 to 20
  if iCurrentPage = i Then
    ' highlight the current page
    ' They're currently ON the current page, so it doesn't have to be a link....
    Response.Write "<bold>" & i & "</bold>&nbsp;"
    Else
    Response.Write "<a href='?offset=" & i & ">" & i & "</a>"
  End If

Next

Else If iCurrentPage > iLastPage - 20 Then
  ' Opposite... this time we are at the END of the page list
  For i = iLastPage-20 to iLastPage
  if iCurrentPage = i Then
    ' highlight the current page
    ' They're currently ON the current page, so it doesn't have to be a link....
    Response.Write "<bold>" & i & "</bold>&nbsp;"
    Else
    Response.Write "<a href='?offset=" & i & ">" & i & "</a>"
  End If

Next

Else If iCurrentPage > 19 and iCurrentPage < iLastPage Then
   ' OK, we're somewhere in the middle... 
   For i = iCurrentPage -10 to iCurrentPage + 10
  if iCurrentPage = i Then
    ' highlight the current page
    ' They're currently ON the current page, so it doesn't have to be a link....
    Response.Write "<bold>" & i & "</bold>&nbsp;"
    Else
    Response.Write "<a href='?offset=" & i & ">" & i & "</a>"
  End If

Next

Essentially, you just have to worry about whether you are close to the beginning or the end.

DISCLAIMER: I haven't tried this code, I just popped it off of the top of my head. I'm not responsible if it breaks something, or makes your cat go bald.

--Greg :)


Just my 2¢
-Cole's Law: Shredded cabbage

--Greg
 
Thanks for the help, I am struggling with the offset and the amount of results per page.

In my code 'recordsonpage' = 14 as I have 14 results on each page so the offset for each link 1,2,3,4 etc goes up 14 each time so link two offset=14, link 3 offset=28 etc.

I can`t figure out where to put this as a for loop increments by 1 each time not 14.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top