PDA

View Full Version : How do I grey out the page number im on using this paging code


murgeltd
06-02-2006, 02:09 PM
The following code is the simplest paging code I have found so far, but how do I grey out (take out link) to page that im already on.

Current Output:
Page: 1/2/3/4

Desired Output:
Page: 1/2/3/4

Current Code:

<%@LANGUAGE=VBScript%>
<!--#include file="../connections/conn_sql.asp" -->
<%
' Define variables
dim recordsonpage, requestrecords, offset, allrecords, hiddenrecords, showrecords, lastrecord, recordcounter, pagelist, pagelistcounter

' records per page
recordsonpage = 3

' count all records
allrecords = 0
set rs = conn.Execute("SELECT * FROM news")
do until rs.EOF
allrecords = allrecords + 1
rs.movenext
loop

' if offset is zero then the first page will be loaded
offset = request.querystring("offset")
if offset = 0 OR offset = "" then
requestrecords = 0
else
requestrecords = requestrecords + offset
end if

' opens database
set rs = conn.Execute("SELECT * FROM news ORDER BY newsPostedDate DESC")

' reads first records (offset) without showing them (can't find another solution!)
hiddenrecords = requestrecords
do until hiddenrecords = 0 OR rs.EOF
hiddenrecords = hiddenrecords - 1
rs.movenext
if rs.EOF then
lastrecord = 1
end if
loop
%>

<html>
<head>
<title>DB Paging</title>
</head>
<body>
<table cellspacing="2" cellpadding="2" border="1" width="400">
<%
' prints records in the table
showrecords = recordsonpage
recordcounter = requestrecords
do until showrecords = 0 OR rs.EOF
recordcounter = recordcounter + 1
%>
<tr>
<td><strong><% = rs("newsSubject") %></strong></br>
<% = rs("newsDesc") %>
</td>
</tr>
<%
showrecords = showrecords - 1
rs.movenext
if rs.EOF then
lastrecord = 1
end if
loop
%>
</table>
<p>
<table cellspacing="2" cellpadding="2" border="1" width="400">
<tr>
<td><% if requestrecords <> 0 then %><a href="newsPaging.asp?offset=<% = requestrecords - recordsonpage %>">Prev Page</a><% else %>Prev Page<% end if %></td>
<td><% if lastrecord <> 1 then %> <a href="newsPaging.asp?offset=<% = requestrecords + recordsonpage %>">Next Page</a><% else %>Next Page<% end if %></td>
</tr>
<tr>
<td colspan="2">pagelist:
<%
pagelist = 0
pagelistcounter = 0
do until pagelist > allrecords
pagelistcounter = pagelistcounter + 1
%>
<a href="newsPaging.asp?offset=<% = pagelist %>"><% = pagelistcounter %></a>
<%
pagelist = pagelist + recordsonpage
loop
%>
</td>
</tr>
</table>

<%
' Closes connection
rs.close
Conn.close
Set rs = Nothing
Set conn = Nothing
%>

</body>
</html>

miranda
06-02-2006, 03:36 PM
I have never seen paging code like this, it works but what if there are thousands of pages of results? If you are on the last page this code will loop through every result in the database and then only display the last results. It is very poorly thought out pagination.

BarrMan
06-02-2006, 08:44 PM
I haven't read your code but this is what i do to get a diferent look for the page you're in.
If request.querystring("page") = i then
response.write "<font color=grey>" & i & "</font>"
Else
Response.write i
End If

murgeltd
06-05-2006, 11:32 AM
Your right about the code. I got it from some website, somewhere on the web.

Can anyone suggest a better solution or place to go for a better coded solution.

Thanks for the code byt the way.

Andy