Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Paging....
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Spoon
Average Member

Ireland
507 Posts

Posted - 02 July 2001 :  07:28:40  Show Profile  Visit Spoon's Homepage  Send Spoon an ICQ Message
Hi, i have a contacts page, and i want to make my own paging system, however, when i pass the page ID to the paging.asp if the page id is 1, or 0, the script works, but when the page id is changed to 6 or 12 etc, the script page will show, but no records...

Please help, here is the code


-----------------------------------

<%
@ LANGUAGE = "VBScript"
ENABLESESSIONSTATE = False
%>
<%
Dim PAGEID,NEXTPAGEID,NEXTPAGELINK,PREVPAGELINK
' Paging Function
PAGEID = Request.Querystring("PAGEID")
If IsEmpty(PAGEID) OR PAGEID = "" OR PAGEID = 0 Then
PAGEID = 1
End IF

'Lets set how many records we want to view
NEXTPAGEID = PAGEID + 4
NEXTPAGELINK = NEXTPAGEID + 1
PREVPAGELINK = PAGEID - 6

'Open the database and use our variables stated above
Set BMWR = Server.CreateObject("ADODB.Recordset")
Set BMW = Server.CreateObject("ADODB.Connection")
BMW.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\admin\dbzz\bmwpublic.mdb"
sqlstmt = "SELECT * from Contacts"
' connect to the database and execute query
BMWR.open sqlstmt, BMW

' if the recordset is empty we will quit
' and display a message using a conditional
' if...then...else statement
If BMWR.eof then
response.write "<center><font face='verdana' size='2'><b>There are no records in the database"
response.write "<br>Please check back later</b></font></center>"
response.end
Else
' close the script for now to add some HTML
%>


<p><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><% If PAGEID >= 1 AND BMWR.EOF = False Then %><a href="paging.asp?PAGEID=<%=NEXTPAGELINK%>">Next Page</a><%Else%> <%End If%> ¦
<% If PAGEID = 1 Then %> <%Else%><a href="paging.asp?PAGEID=<%=PREVPAGELINK%>">Previous Page</a><%End If%></font></p>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="2">-------------------------------------------</font></p>

<%
' loop through the records and display the information
' using a Do While...Loop statement
Do While PAGEID <= NEXTPAGEID AND NOT BMWR.eof
Dim ID, name, title, email, phone

ID = BMWR("ID")
name = BMWR("name")
title = BMWR("title")
email = BMWR("email")
phone = BMWR("phone")

PAGEID = PAGEID + 1


' close the script for now to write in some HTML
%>


<%= title %><br>
<%= name %><br>
<%= phone %><br>
<%= email %><br>

<%
' move to the next record
BMWR.MoveNext
' go get another record
loop


End If
%>
<%
BMWR.close
Set BMWR = Nothing
BMW.Close
Set BMW = Nothing
%>

----------------------------



Can anyone help me out, is it something to do with the sql statament??
Thx guys (and girls )

Spoon

"uohh look at me, ive got a signature, uohh look at me!" :)

Spoon
Average Member

Ireland
507 Posts

Posted - 03 July 2001 :  06:46:44  Show Profile  Visit Spoon's Homepage  Send Spoon an ICQ Message
Its ok guys, i figured it out

The code now does previous and next pages, gives it a record number (not an ID although you could impliment it easy!) and tells you which records you are displaying out of how many there is. (you are displaying, 6 - 10 of 11 records etc)

If anybody wants to see the code please post here and ill paste it

"uohh look at me, ive got a signature, uohh look at me!" :)
Go to Top of Page

work mule
Senior Member

USA
1358 Posts

Posted - 03 July 2001 :  10:22:14  Show Profile

PAGEID = Request.Querystring("PAGEID")

'Lets set how many records we want to view
NEXTPAGEID = PAGEID + 4
NEXTPAGELINK = NEXTPAGEID + 1
PREVPAGELINK = PAGEID - 6

sqlstmt = "SELECT * from Contacts"


' loop through the records and display the information
' using a Do While...Loop statement
Do While PAGEID <= NEXTPAGEID AND NOT BMWR.eof
Dim ID, name, title, email, phone

ID = BMWR("ID")
name = BMWR("name")
title = BMWR("title")
email = BMWR("email")
phone = BMWR("phone")

PAGEID = PAGEID + 1

' move to the next record
BMWR.MoveNext
' go get another record
loop



Okay, I've trimmed down your example above for this discussion. I don't see how this would work for you.

You retrieve all records from the database. Then your loop displays all records until "PAGEID <= NEXTPAGEID". So here's what I see happening:

PageID = 1; NextPageID = 5; Recs displayed = 5
PageID = 6; NextPageID = 10; Recs displayed = 10
PageID = 8; NextPageID = 12; Recs displayed = 12

I don't see anywhere where the starting point is determined. Snitz has some very nice paging code on some of the pages. I would recommend taking a look at a couple pages from the forum.




The Work Mule Forums
The Writer Community
Go to Top of Page

mafifi
Junior Member

USA
308 Posts

Posted - 03 July 2001 :  12:21:48  Show Profile  Send mafifi an ICQ Message
Try the following from http://www.asp101.com/samples/db_paging.asp and it worked for me.

Thanks,

Mo

Edited by - mafifi on 03 July 2001 12:23:07
Go to Top of Page

Spoon
Average Member

Ireland
507 Posts

Posted - 03 July 2001 :  13:08:49  Show Profile  Visit Spoon's Homepage  Send Spoon an ICQ Message
Yeah i understand that now,
HEre its the code anyhow, Its trimmed down, cut out most of html
------------------------------
Code Start
------------------------------

 

<%
@ LANGUAGE = "VBScript"
ENABLESESSIONSTATE = False
%>
<%
Dim BMW,BMWR
Set BMWR = Server.CreateObject("ADODB.Recordset")
Set BMW = Server.CreateObject("ADODB.Connection")
BMW.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\admin\dbzz\bmwpublic.mdb"

Dim sqlstmt
sqlstmt = "SELECT * from Contacts"
BMWR.open sqlstmt, BMW, 3, 1, 1

Dim RECORDCOUNT
RECORDCOUNT = BMWR.Recordcount
'----------------------------
'code to show what records we are using
'----------------------------

Dim PAGEID,NEXTLOOPID,COUNTTO,NEXTPAGELINK,PREVPAGELINK
PAGEID = Request.Querystring("PAGEID")
If IsEmpty(PAGEID) OR PAGEID = "" OR PAGEID = 0 Then
PAGEID = 1
End IF

NEXTLOOPID = PAGEID + 4
COUNTTO = NEXTLOOPID
If COUNTTO > RECORDCOUNT Then
COUNTTO = RECORDCOUNT
End If

NEXTPAGELINK = NEXTLOOPID + 1
If NEXTPAGELINK > RECORDCOUNT Then
NEXTPAGELINK = NEXTPAGELINK + 1
End If

PREVPAGELINK = PAGEID - 5
If PAGEID = 6 Then
PREVPAGELINK = PAGEID - 6
End IF

'-------------------------------
' Code to actually page it
'-------------------------------
Dim PAGESIZE,PAGEINDEX,RECORDNUMER

PAGESIZE = 5 ' Show how many items we want to show on each page
PAGEINDEX = Request("PAGEINDEX")
'If pageIndex is empty, set it to one.
if PAGEINDEX = "" then PAGEINDEX = 1

RECORDNUMBER = (PAGEINDEX * PAGESIZE) - (PAGESIZE) ' Use this math to find the record number

BMWR.PageSize = PAGESIZE ' Set the number of records per page
BMWR.AbsolutePage = PAGEINDEX 'Define what page number on which the current record resides.


'----------------
'Make Pageindex link
'----------------

Dim PAGEINDEXPREV,PAGEINDEXNEXT

PAGEINDEXPREV = PageIndex - 1
PAGEINDEXNEXT = PageIndex + 1 'same as BMWR.AbsolutePage
' Dont need to worry about if we are at the start or end of the db
' It wont be displayed as we have taken care of this with nextpagelink and
'prevpagelink above. Also formatted in links below :)


'--------------------------
'Use a procedure to change font color of text that has showing records x to y out of z
'How customizable :)
'--------------------------------


Sub WRITECOLOR
Response.Write "<font color='silver'>"
End Sub

Sub ENDWRITECOLOR
Response.Write "</font>"
End Sub

' If there is no records in the database
If BMWR.eof then
response.write "<center><font face='verdana' size='2'><b>There are no records in the database"
response.write "<br>Please check back later</b></font></center>"
response.end
Else

%>



<p><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<% If RECORDCOUNT < NEXTPAGELINK Then%>
<%Else%>
<a href="default.asp?PAGEID=<%=NEXTPAGELINK%>&PAGEINDEX=<%=PAGEINDEXNEXT%>">Next
Page<font size="1"> >>></font></a> ¦
<%End If%>
<% If PAGEID = 1 Then %>
<%Else%>
<a href="default.asp?PAGEID=<%=PREVPAGELINK%>&PAGEINDEX=<%=PAGEINDEXPREV%>"><font size="1"><<<</font>
Previous Page</a>
<%End If%>
</font></p>


<div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF"><b>Currently
Display Records #
<%CALL WRITECOLOR%>
-<%= PAGEID%>-
<%CALL ENDWRITECOLOR%>
to #
<%CALL WRITECOLOR%>
-<%= COUNTTO%>-
<%CALL ENDWRITECOLOR%>
</b><b> </b></font></div>

<%

COUNT = 1
do while NOT BMWR.EOF AND COUNT <= PAGESIZE
With Response
.Write"<tr bgcolor='#ffffcc'>"
.Write "<td width='4%' bgcolor='#FFCCFF'><div align='center'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'><a href='editcontacts.asp?ID="& BMWR("ID") &"'><img src='edit.gif' width='15' height='15' border='0'></a></font></div></td>"
.Write "<td width='3%'><center><font face='verdana' size='1'>" & RECORDNUMBER + COUNT & "</font></center></td>"
.Write "<td width='22%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>" & BMWR("title") & "</font></td>"
.Write "<td width='22%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>" & BMWR("name") & "</font></td>"
.Write "<td width='22%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>" & BMWR("email") & "</font></td>"
.Write "<td width='22%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>" & BMWR("phone") & "</font></td>"
.Write "<td width='4%' bgcolor='#FFCCFF'><div align='center'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'><a href='deletecontacts.asp?ID=" & BMWR("ID") & "&name=" & BMWR("name") & "&title=" & BMWR("title") & "&status=NO'><img src='delete.gif' width='14' height='15' alt='Delete this contact' border='0'></a></font></div></td>"
.write "</tr>"
End with
COUNT = COUNT + 1
BMWR.MoveNext
loop
End IF

%>





"uohh look at me, ive got a signature, uohh look at me!" :)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.35 seconds. Powered By: Snitz Forums 2000 Version 3.4.07