Hey I have a comments page that displays all the comments in my database, problem is all of them appear on the page so it's super long. How do I only show 10 comments per page, and at the bottom is view page 1,2,3,4,....
that i want to appear automatically without having to code that in as the database grows, i need it to be dynamic as the database grows. Some sample code would be great too. Thx.
Come on ribeye I know you have the answer!!
here is the code i retrieve from www.aspfaq.com . I used this example then worked from there.
set conn = Server.CreateObject("ADODB.Connection")
' tell me how many records you want per page
perPage = 50
' set up a query to get the count, and another to get the data
countSQL = "SELECT count(artist) FROM CDs"
dataSQL = "SELECT artist,title,cdn FROM CDs"
' start getting the data, first we need to know the count
' this will tell us how many pages there will be
set rs = conn.execute(countSQL)
counter = clng(rs(0))
rs.close: set rs = nothing
' determine if anything is returned. If there are records,
' figure out the pagecount and the total number of records.
if counter < 1 then
Response.Write "No records found."
if counter = 1 then perpage = 1
totalRecords = counter
pageCount = clng(counter/perpage)
if counter/perPage > pageCount then
pageCount = pageCount + 1
' what page are we on?
currentpage = clng(request.form("currentpage"))
if currentpage <= 1 then
currentpage = 1
elseif currentpage > pageCount then
currentpage = pagecount
cp = currentPage
response.Write "<form method=post action=rsPage.asp "
response.Write "name=spform><b>Aaron's CDs</b> ... "
response.Write "count = " & counter & "</b> ... Jump to"
response.Write " page #<select name=currentpage "
for i = 1 to pageCount
thisOpt = "<option value='" & i & "'>" & i
' highlight the current page!
response.Write replace(thisOpt," value='" & cp &_
"'", " value='" & cp & "' SELECTED")
Response.Write "<p><table border=0 cellpadding=4 "
Response.Write "cellspacing=0 style='border:1px solid #999999'>"
' set up the first record to move to, if applicable
if pageCount > 1 then
startrecord = (clng(currentpage-1) * perpage) + 1
' let's get the data, move to the first record if necessary
' loop through, returning records until we meet perpage or EOF
set rs = conn.execute(dataSQL)
'if counter > perpage and startrecord > 1 then
for x = 1 to perpage
if rs.eof then exit for
response.write "<tr valign=middle><td>"
artist = rs(0)
if artist <> prevArtist then
prevArtist = artist
if rs(2) then
artist = "<img src=leaf.gif><b>" & artist & "</b>"
artist = "<b>" & artist & "</b>"
artist = " <span style='color:#999999'>" & artist & "</span>"
response.write "<nobr>" & artist & "</nobr></td><td>"
response.write "<nobr>" & rs(1) & "</nobr></td></tr>"
' clean up
rs.close: set rs = nothing
conn.close: set conn = nothing
Here is the code I've tried switching the code around but when I've tried switching the code around so it's put where it isn't open and I get error object required. I've tried closing it and I get same error below but when object is closed. I'm loosing more hair here. This code is from Dave, so he may know, and I know ribby always has the answer! thanks guys
Operation is not allowed when the object is open.
/hunting/wwwroot/View_Comments.asp, line 15
Dim dbConn, dbQuery, recordsetDB, strComments, strQueryString1,strUser_Id
Dim Hunt_Id, Hunt_Password, numPages, curPage
Set dbConn = Server.CreateObject("ADODB.Connection")
Call dbConn.Open ("Appdb1","Anyone","Anyone")
strquerystring1 = "SELECT Comments.Comments, Comments.Hunt_Id FROM Comments "
set recordsetDB = dbconn.execute(strquerystring1)
IT DOESN"T LIKE THIS LINE UNDERNEATH
RecordsetDB.CursorLocation = 3
RecordsetDB.PageSize = 10
numPages = RecordsetDB.PageCount
curPage = CInt(Request.QueryString("Page"))
If curPage < 1 Then curPage = 1
If curPage > numPages Then curPage = numPages
RecordsetDB.AbsolutePage = curPage
Page <%=curPage%> of <%=numPages%>
<%Do While recordsetDB.AbsolutePage = curPage And NOT recordsetDB.EOF%>
Ok the user id and pass are passed to the first page and I can physically see them, as soon as I press page next, last page, etc.. they dissapear totally, nothing is getting passed after I press those buttons, I've moved the <input type="text" name="OldHunt_Id" size="24" Value="<%=Hunt_Id%>"> and requestl.form line to every possible location i can think of, no results.
strquerystring1 = "SELECT Stories.Stories, Stories.Hunt_Id FROM Stories "
Set recordsetDB = server.createObject("ADODB.recordset")
recordsetDB.Open strquerystring1, dbconn
numpages = recordsetDb.PageCount
CurPage = CInt(request.querystring("Page"))
If curpage < 1 Then Curpage = 1
If curpage > Numpages Then Curpage = Numpages
recordsetDB.AbsolutePage = Curpage
Page <%=CurPage%> Of <%=NumPages%>
<% Do While recordsetDb.AbsolutePage = Curpage AND NOT recordsetDB.EOF%>
<table border="3" width="504" height="100" bordercolordark ="darkGreen" bordercolorlight="lightgreen">
strStories = recordsetDB("Stories").VALUE
strUser_Id = recordsetDB("Hunt_Id").Value %>
Submitted by <% response.write ""& strUser_Id & "" %><P>
<%response.write ""& strStories &"" %>
<form Name ="Navigate" METHOD="POST" ACTION="View_Storie.asp" onSubmit="return false;">
i ran this code and it works fine with me. I set up a test database created your table added in data ran the page, all the buttons are there, the record count is correct, all the button are working and done what they are ment to do. I never got any errors and none of the buttons disapeared. Is it not working for you?