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

Prev - Next page options

Status
Not open for further replies.

theScien

Technical User
Aug 27, 2003
98
PT
Hi all.

I'm developing a small news system, and it's all done apart from the options to go back and forward with records, just like on top of this forums (Prev 1 2 3 4 5 Next) sort of thing.

I'm using ASP, developing it with Access for now, but will use MySQL when done.

Here's the bit I have done:

<%
newsPERpage = 5

Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.MapPath(&quot;news.mdb&quot;)

'Count records
SQL = &quot;SELECT COUNT(fld_newsID) AS recTOTAL FROM tbl_NEWS&quot;
Set RS = Conn.Execute(SQL)
totalREC = RS(&quot;recTOTAL&quot;)

'Obtain list
SQL = &quot;SELECT * FROM tbl_NEWS ORDER BY fld_newsID DESC&quot;
Set RS = Conn.Execute(SQL)
%>

<TABLE ALIGN=&quot;center&quot; BORDER=&quot;0&quot; CELLPADDING=&quot;0&quot; CELLSPACING=&quot;0&quot;>
<TR>
<TD>Posts per page: <%= newsPERpage %> - Total posts: <%= totalREC %> - Need to generate <%= totalREC / newsPERpage %> pages.</TD>
</TR>
</TABLE>
<BR>

<TABLE ALIGN=&quot;center&quot; BORDER=&quot;0&quot; CELLPADDING=&quot;0&quot; CELLSPACING=&quot;0&quot;>
<TR>
<TD>Page: |
<%
For nPAGE = 1 to totalREC / newsPERpage
procPAGE = nPAGE
If Len(procPAGE) = 1 Then
procPAGE = &quot;0&quot; & procPAGE
End If
%>
<A HREF=&quot;news_list.asp&goPAGE=<%= nPAGE %>&quot;><%= procPAGE %></A> |
<%
Next
%>
</TD>
</TR>
</TABLE>
<BR>

<%
Do While Not RS.Eof

'News records go here

RS.MoveNext
Loop

RS.Close
Set RS = Nothing
Conn.Close
Set Conn = Nothing
%>

I think my approach so far is correct, but can't think of a way to make it work from here.

All help is appreciatted.

Thank you.

If you haven't heard of it, then you most likely don't need it.
---------------------------------------------------------------------
---------------------------------------------------------------------
 
I used this code as a start point
and modified it to get this,
to pull data from 2 tables

If and when you move to MySQL uncomment the useCursorLocation line as well otherwise the AbsolutePage Method will throw an error.




Chris.

Indifference will be the downfall of mankind, but who cares?
 
Thanks Chris, looked at that code, and it won't work with MySQL, anyway, after much fidling about I moved the tests to MySQL, and I came up with some pretty interesting solutions, almost fully working, check it here:

===========================================================
<%
'Options
newsPERpage = 4

'Read page to go
urlPAGE = Request.QueryString(&quot;goPAGE&quot;)

'Assume default page
If urlPAGE = &quot;&quot; Then
urlPAGE = 0
End If
%>

<HTML>
<HEAD>
<TITLE>List!</TITLE>
</HEAD>
<BODY BGCOLOR=&quot;#BFD0DA&quot;>

<!--#include file=&quot;news_conn.inc&quot; -->

<%
'Count records
SQL = &quot;SELECT COUNT(fld_propaID) AS recTOTAL FROM tbl_PROPA&quot;
Set RS = Conn.Execute(SQL)
totalREC = RS(&quot;recTOTAL&quot;)

'Obtain list - LIMIT starting from 0, number to show
SQL = &quot;SELECT * FROM tbl_PROPA ORDER BY fld_propaID DESC LIMIT &quot; & urlPAGE * newsPERpage & &quot;, &quot; & newsPERpage & &quot;&quot;
Set RS = Conn.Execute(SQL)

totalPAGES = totalREC / newsPERpage

'Always round up totalPAGES value and discard decimals
If Len(totalPAGES) => 3 Then
totalPAGES = Int(totalPAGES) + 1
End If
%>

<TABLE ALIGN=&quot;center&quot; BORDER=&quot;0&quot; CELLPADDING=&quot;0&quot; CELLSPACING=&quot;0&quot;>
<TR>
<TD>News per page: <%= newsPERpage %> - Total news: <%= totalREC %> - Need to generate <%= totalPAGES %> pages.</TD>
</TR>
</TABLE>
<BR>

<TABLE ALIGN=&quot;center&quot; BORDER=&quot;0&quot; CELLPADDING=&quot;0&quot; CELLSPACING=&quot;0&quot;>
<TR>
<TD>Page: | <A HREF=&quot;news_list.asp?goPAGE=0&quot;><B>01</B></A> |
<%
For nPAGE = 1 to totalPAGES - 1
procPAGE = nPAGE + 1
If Len(procPAGE) = 1 Then
procPAGE = &quot;0&quot; & procPAGE
End If
%>
<A HREF=&quot;news_list.asp?goPAGE=<%= nPAGE %>&quot;><B><%= procPAGE %></B></A> |
<%
Next
%>
</TD>
</TR>
</TABLE>
<BR>

<%
Do While Not RS.Eof

'News record loop

RS.MoveNext
Loop

RS.Close
Set RS = Nothing
Conn.Close
Set Conn = Nothing
%>
</BODY>
</HTML>
===========================================================

In MySQL I can use the very useful LIMIT in the SQL query.

By the way, I couldn't find a function in ASP to always round up non integer values, I tried Round() and Fix() but they don't do a forced round up as it is needed in my scenario, for instances, they round alright 1.4 to 1 and 1.6 to 2, but what I need is a function to force the round of 1.1 to 2 regardless, so I have come up with a temporariliy solution as you can see in the code above, but it only works up to 99.x, if the value is 123.4 it fails. Does any one know of a function that will always round UP a non integet value?

Also in my DB paging, it needs a limit on the page list, say if there are 200 records to return and it is set to show 10 per page, the page list will have 20 links (1 2 3 4 ...), how can I limit it to always have only, say, 10 links? Plus, how to enable a Prev...Next functionality? Also have the link to the page that's being viewed not clickable?

These are the things that still need to be done, apart from it, it works fine, give it a try.

What do you mean to use the (CursorLocation)? What does it do?

Thanks.

If you haven't heard of it, then you most likely don't need it.
---------------------------------------------------------------------
---------------------------------------------------------------------
 
Is this the line you want to force to round up?
[tt]totalPAGES = totalREC / newsPERpage[/tt]

Unfortunately VBscript doesn't appear to have a CEILING() function (SQL Server does) that would do what you want.

You can do it yourself I guess..
Code:
if totalRec % newsPERpage = 0 then
  'this means remainder of 0, so divides nicely
  totalPages = totalRec / newsPERpage
else
  'need to round up. just force to (rounded down) int then add +1 ?
  totalPages = Int(totalRec / newsPERpage) + 1
end if

untested, so let us know if it helps.

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Thanks, so there's no always round up function in VBscript? Just as I suspected, if your
Code:
( If...Then )
works all the time then problem solved, it works well so far.

What about only having 10 linkable pages to choose from, (1 2 3 4 ...) instead of all of them?

Thanks once again.

If you haven't heard of it, then you most likely don't need it.
---------------------------------------------------------------------
---------------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top