Easiest Code for Database Paging

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • M P

    Easiest Code for Database Paging

    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


  • Vilmar Brazão de Oliveira

    #2
    Re: Easiest Code for Database Paging

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

    <%@LANGUAGE="VB SCRIPT" CODEPAGE="1252" %>
    <%
    Option Explicit 'força declaração de variável, TEM QUE SER A 1ª DECLARAÇÃO
    APÓS A DIRETIVA @LANGUAGE...... .
    Response.Expire s = -1 'evita cache no servidor, mostra a versão mais atual
    da página.
    %>
    <html>
    <head>
    <title>Exempl o de P&aacute;gina&c cedil;&atilde;o </title>
    </head>
    <!-- #include file="adovbs.in c" -->
    <!-- #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(iPageSiz e)
    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.QuerySt ring("PaginaMos trada") = "" Then
    iPageCurrent = 1
    Else
    iPageCurrent = CInt(Request.Qu eryString("Pagi naMostrada"))
    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,AtCo ntato,AtServico ,AtSolucionado, AtSolicitacao,A t
    Descr,AtSolucao ,AtAtendente from HT_DBAU001_DAte nd WHERE AtCod = 5000 ORDER
    BY AtDtAtend"
    'Response.Write "<b>strSQL</b>:<br>" & strSQL & "<BR>"
    'Response.End()

    Set Rs = Server.CreateOb ject("adodb.rec ordset") '»»É preciso declarar o
    recordset dessa forma qdo. usa-se RS.Open
    Rs.CursorLocati on = adUseClient
    Rs.CursorType = adOpenForwardOn ly 'tipo do cursor
    Rs.LockType = adLockOptimisti c '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(Mostrad o,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_pag inacao.asp?Pagi naMostrada=<%= 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_pag inacao.asp?Pagi naMostrada=<%=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_pag inacao.asp?Pagi naMostrada=<%=i PageCurrent + 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


    "M P" <mark@textguru. ph> escreveu na mensagem
    news:OfnYHdLAEH A.1548@TK2MSFTN GP12.phx.gbl...[color=blue]
    > 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
    >
    >[/color]


    Comment

    • Jeff Cochran

      #3
      Re: Easiest Code for Database Paging

      On Wed, 3 Mar 2004 08:35:41 +0800, "M P" <mark@textguru. ph> wrote:
      [color=blue]
      >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.[/color]

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

      One good example is:



      You may wish to do this client side, thusly:

      eSports News, Results, upcoming Matches & live Matches. Learn tricks and guides in the esports space. ✅ We cover CS:GO, Dota 2, LOL, Overwatch & PUBG. 


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

      Jeff

      Comment

      Working...