Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) Paginação


Legionáriors

Pergunta

Bom dia pessoal,

Tenho o seguinte script que quando atinge o número máximo de ´fotos a serem exibidas ele dá a mensagem "No Records Found" dizendo que não há mais imagens ele lista a quantidade de páginas exemplo 1 2 3 >> Next mas quando mudo para a página 2 ele dá a dita mensagem e não mostra nada, será que alguém pode olhar e me ajudar para resolver isso???

Obrigado a quem poder ajudar.

<!--VB ADO Constants file.  Needed for the ad... constants we use-->
<!-- #include file="Admin/adovbs.inc" -->
<%
' BEGIN USER CONSTANTS
Dim CONN_STRING
Dim CONN_USER
Dim CONN_PASS



CONN_STRING = "DBQ=" & Server.MapPath("database.mdb") & ";"
CONN_STRING = CONN_STRING & "Driver={Microsoft Access Driver (*.mdb)};"

' This DB is unsecured, o/w you'd need to specify something here
CONN_USER = ""
CONN_PASS = ""




' BEGIN RUNTIME CODE
' Declare our vars
Dim iPageSize       'How big our pages are
Dim iPageCount      'The number of pages we get back
Dim iPageCurrent    'The page we want to show
Dim strOrderBy      'A fake parameter used to illustrate passing them
Dim rstSimple          'SQL command to execute
Dim objPagingConn   'The ADODB connection object
Dim objPagingRS     'The ADODB recordset object
Dim iRecordsShown   'Loop controller for displaying just iPageSize records
Dim I               'Standard looping var

' Get parameters
iPageSize = 10 ' You could easily allow users to change this

' Retrieve page to show or default to 1
If Request.QueryString("page") = "" Then
    iPageCurrent = 1
Else
    iPageCurrent = CInt(Request.QueryString("page"))
End If





' This is where you read in parameters you'll need for your query.
' Read in order or default to id
If Request.QueryString("order") = "" Then
    strOrderBy = "id"
Else
    strOrderBy = Request.QueryString("order")
End If


strSQL = "SELECT * FROM cats WHERE cat = '" & Request.QueryString("cat") & "' ORDER BY ID;"




' Now we finally get to the DB work...
' Create and open our connection
Set objPagingConn = Server.CreateObject("ADODB.Connection")
objPagingConn.Open CONN_STRING, CONN_USER, CONN_PASS

' Create recordset and set the page size
Set objPagingRS = Server.CreateObject("ADODB.Recordset")
objPagingRS.PageSize = iPageSize

' You can change other settings as with any RS
'objPagingRS.CursorLocation = adUseClient
objPagingRS.CacheSize = iPageSize

' Open RS

objPagingRS.Open strSQL, objPagingConn, adOpenStatic, adLockReadOnly, adCmdText

' Get the count of the pages using the given page size
iPageCount = objPagingRS.PageCount

' If the request page falls outside the acceptable range,
' give them the closest match (1 or max)
If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
If iPageCurrent < 1 Then iPageCurrent = 1

' Check page count to prevent bombing when zero results are returned!
If iPageCount = 0 Then
    Response.Write "No records found!"
Else
    ' Move to the selected page
    objPagingRS.AbsolutePage = iPageCurrent

    ' Start output with a page x of n line
    %>
<head>
<STYLE fprolloverstyle>A:hover {color: red}
</STYLE>

</head>

    <p>
    <font face=verdana size=2><b>Página <%= iPageCurrent %> de <%= iPageCount %></font></b>
    </p>
    

    <%
    
    For I = 0 To objPagingRS.Fields.Count - 1
        
    Next 'I
    
    ' Loop through our records and ouput 1 row per record
    iRecordsShown = 0
    Do While iRecordsShown < iPageSize And Not objPagingRS.EOF
%>


  <table border="0" width="100%" cellpadding="0">
  <tr>
    <td width="100%" bgcolor="Silver">
      <table border="0" width="100%" cellspacing="5" cellpadding="5">
        <tr>
          <td width="20%">
            <p style="margin: 15"><a href="big.asp?id=<%= objPagingRS.Fields("ID").Value %>"><img border="0" src="<%= objPagingRS.Fields("pic_url").Value %>" height="120"></a></td>
          <td width="80%">
            <p style="margin-left: 15"><font face="Verdana" size="2" color="white"><b><%= objPagingRS.Fields("pic_dis").Value %></b></font></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td width="100%" bgcolor="Silver">
      <p align="left" style="margin-left: 10; margin-right: 7; margin-top: 2; margin-bottom: 2"><a href="big.asp?id=<%= objPagingRS.Fields("ID").Value %>" style="text-decoration:none"><b><font face="Verdana" color="white" size="2"><%= objPagingRS.Fields("pic_name").Value %></a></font></b></td>
  </tr>
</table>

<p align="center">


<%    
    iRecordsShown = iRecordsShown + 1
    objPagingRS.MoveNext
    Loop
%>

<% End If

' Close DB objects and free variables
objPagingRS.Close
Set objPagingRS = Nothing
objPagingConn.Close
Set objPagingConn = Nothing


' Show "previous" and "next" page links which pass the page to view
' and any parameters needed to rebuild the query.  You could just as
' easily use a form but you'll need to change the lines that read
' the info back in at the top of the script.
If iPageCurrent > 1 Then
    %>
 <a href="list.asp?page=<%= iPageCurrent - 1 %>&order=<%= Server.URLEncode(strOrderBy) %>">&lt;&lt;
 Prev</a>
    <%
End If

' You can also show page numbers:
For I = 1 To iPageCount
    If I = iPageCurrent Then
        %>
        <%= I %>
        <%
    Else
        %>
        <a href="list.asp?page=<%= I %>&order=<%= Server.URLEncode(strOrderBy) %>"><%= I %></a>
        <%
    End If
Next 'I

If iPageCurrent < iPageCount Then
    %>
 <a href="list.asp?page=<%= iPageCurrent + 1 %>&order=<%= Server.URLEncode(strOrderBy) %>">Next &gt;&gt;</a>
<%
End If


%>

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

Visitante
Este tópico está impedido de receber novos posts.


  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...