Easiest Code for Database Paging

M

M P

Can anyone help me find a code for Database Paging?

I have seen some of it but its very hard for me to read, its too advance.
Need to have a code with beginner to intermediate level.

thanks,

Mark
 
V

Vilmar Brazão de Oliveira

Hi, I am passing for you a code in vbscript easy, so you can translate it to
jscript, follows:
---------------------

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Option Explicit 'força declaração de variável, TEM QUE SER A 1ª DECLARAÇÃO
APÓS A DIRETIVA @LANGUAGE.......
Response.Expires = -1 'evita cache no servidor, mostra a versão mais atual
da página.
%>
<html>
<head>
<title>Exemplo de P&aacute;gina&ccedil;&atilde;o</title>
</head>
<!-- #include file="adovbs.inc" -->
<!-- #include file="conn_dbAT.asp" -->
<body>
<%
'Variáveis de páginação
Dim iPageSize 'Define quão grande será cada página
Dim iPageCount 'O nº de páginas para se movimentar pelo recordset
Dim iPageCurrent 'A página corrente(atual)
Dim strSQL 'String SQL a ser executada
Dim Rs 'Objeto de recordset
Dim iRecordsShown 'Controlador de loop p/ mostrar exatamente os registros
de cada tamanho de página(iPageSize)
Dim I 'Usada no loop dos laços for
Dim Mostrado 'Registro mostrado na tela

'»»Parâmetros passados para paginação
iPageSize = 10 'Aqui pode-se aumentar ou diminuir o nº de registros por
página.

'Recupera página p/ apresentar ou seta como default 1 a página atual
If Request.QueryString("PaginaMostrada") = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(Request.QueryString("PaginaMostrada"))
End If
'»»Parâmetros passados para paginação

'SE FOREM USADOS PARÂMETROS NA CONSULTA SQL, SERÁ PRECISO PASSÁ-LOS NA URL
strSQL = "Select
ATCod,AtDtAtend,AtHrAtend,AtContato,AtServico,AtSolucionado,AtSolicitacao,At
Descr,AtSolucao,AtAtendente from HT_DBAU001_DAtend WHERE AtCod = 5000 ORDER
BY AtDtAtend"
'Response.Write "<b>strSQL</b>:<br>" & strSQL & "<BR>"
'Response.End()

Set Rs = Server.CreateObject("adodb.recordset") '»»É preciso declarar o
recordset dessa forma qdo. usa-se RS.Open
Rs.CursorLocation = adUseClient
Rs.CursorType = adOpenForwardOnly 'tipo do cursor
Rs.LockType = adLockOptimistic 'tipo de bloqueio do cursor
Rs.CacheSize = iPageSize
Rs.PageSize = iPageSize
Rs.Open strSQL,Conexao '»»Abre-se o recordset desta forma qdo. precisa de
usar seus vários métodos e propridades

'Contador de páginas
iPageCount = Rs.PageCount

'Se houver mais páginas a serem exibidas, a pág. corrente será = ao contador
de pág.
If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
'Se não houver mais páginas a serem exibidas, a página corrente será 1
If iPageCurrent < 1 Then iPageCurrent = 1

'Verifique a contagem da página para impedir bombardear quando os resultados
zero são retornados!
If iPageCount > 0 Then
' Move para página selecionada.
Rs.AbsolutePage = iPageCurrent
'Inicia saída com uma Página X de N linha
%>
<p>
<font size="3">Página <strong><%= iPageCurrent %></strong>
de <strong><%= iPageCount %></strong></font>
</p>
<%
'Loop através dos registros e saída 1 linha por registro
iRecordsShown = 0
Do While iRecordsShown < iPageSize And Not Rs.EOF
Mostrado = Rs("AtContato") & ""
Mostrado = Replace(Mostrado,Chr(0),"")
Response.Write "<b>Nome:</b>&nbsp;" & Mostrado & "<br>"
' Incrementa o nº de registros apresentados
iRecordsShown = iRecordsShown + 1
'Não esquecer de mover p/ próximo registro!
Rs.MoveNext
Loop
End If
Response.Write "<br><br>"

'»»INÍCIO: Mostrar links anterior e próxima e nºs de página.
If iPageCurrent > 1 Then '»»Mostra link p/ pág. anterior.
%>
<a href="exemp_paginacao.asp?PaginaMostrada=<%= iPageCurrent - 1
%>">[&lt;&lt; Anterior]</a>
<%
End If

'»»INÍCIO: Apresentar nº de páginas.
For I = 1 To iPageCount
'Só montará link c/ o Nº da pág. se não for a pág. corrente
If I = iPageCurrent Then
Response.Write "<strong>" & I & "</strong>"
Else
%>
<a href="exemp_paginacao.asp?PaginaMostrada=<%=I%>"><%=I%></a>
<%
End If
Next
'»»FIM: Apresentar nº de páginas.

If iPageCurrent < iPageCount Then '»»Mostra link p/ pág. posterior.
%>
<a href="exemp_paginacao.asp?PaginaMostrada=<%=iPageCurrent + 1%>">[Próxima
&gt;&gt;]</a>
<%
End If
'»»FIM: Mostrar links anterior e próxima e nºs de página.
%>
</body>
</html>

--

Bye,

««««««««»»»»»»»»»»»»»»
Vlmar Brazão de Oliveira
Desenvolvimento Web
HI-TEC
 
J

Jeff Cochran

Can anyone help me find a code for Database Paging?

I have seen some of it but its very hard for me to read, its too advance.
Need to have a code with beginner to intermediate level.

It's quite possible that's because there is no "beginner" code for
database paging. :)

One good example is:

http://www.asp101.com/samples/db_paging.asp

You may wish to do this client side, thusly:

http://www.4guysfromrolla.com/webtech/050901-1.shtml

Otherwise, aspfaq.com, aspin.com and a Google for "ASP Database
Paging" will turn you on to many options.

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top