Foros del Web » Programando para Internet » ASP Clásico »

ayuda con paginación

Estas en el tema de ayuda con paginación en el foro de ASP Clásico en Foros del Web. Saludos colegas, estoy intentando paginar este trabajo pero no me sale sera que me pueden echar una mano, lo que quiero es que si hay ...
  #1 (permalink)  
Antiguo 20/01/2010, 06:56
 
Fecha de Ingreso: diciembre-2009
Mensajes: 85
Antigüedad: 14 años, 4 meses
Puntos: 0
Exclamación ayuda con paginación

Saludos colegas, estoy intentando paginar este trabajo pero no me sale sera que me pueden echar una mano, lo que quiero es que si hay 200 datos en mi base de datos pues me muestre 10 en cada pagina.. espero me puedan ayudar
************DODIGO*****parte 1******
<%
set rsLink = Server.CreateObject("ADODB.Recordset")
rsLink.ActiveConnection = MyConnString
rsLink.Source = "SELECT CAT_ID, foto, SUB_ID, LINK_APPROVED, LINK_DATE, LINK_DESC, LINK_EMAIL, LINK_ID, LINK_NAME, (LINK_RATE/NO_RATES) AS RATING, LINK_RATE, LINK_URL, NO_HITS, NO_RATES, SUB_ID, TOTAL_COMMENTS FROM LINKS WHERE LINK_APPROVED = 1 ORDER BY LINK_DATE DESC"
rsLink.CursorType = 0
rsLink.CursorLocation = 2
rsLink.LockType = 3
rsLink.Open()
rsLink_numRows = 0
%>
<%
'repeat2_numRows= cantidad de items que se reflejan en pantalla....
Dim Repeat2__numRows
Repeat2__numRows = 25
Dim Repeat2__index
Repeat2__index = 0
rsLink_numRows = rsLink_numRows + Repeat2__numRows
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

' set the record count
rsLink_total = rsLink.RecordCount

' set the number of rows displayed on this page
If (rsLink_numRows < 0) Then
rsLink_numRows = rsLink_total
Elseif (rsLink_numRows = 0) Then
rsLink_numRows = 1
End If

' set the first and last displayed record
rsLink_first = 1
rsLink_last = rsLink_first + rsLink_numRows - 1

' if we have the correct record count, check the other stats //
'si tenemos el número de registros correcto, consulte las estadísticas de otros
If (rsLink_total <> -1) Then
If (rsLink_first > rsLink_total) Then rsLink_first = rsLink_total
If (rsLink_last > rsLink_total) Then rsLink_last = rsLink_total
If (rsLink_numRows > rsLink_total) Then rsLink_numRows = rsLink_total
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them
'si no sabemos el número de registros, de forma manual contarlos

If (rsLink_total = -1) Then

' count the total records by iterating through the recordset
''Contar los registros totales de la iteración a través de los registros
rsLink_total=0
While (Not rsLink.EOF)
rsLink_total = rsLink_total + 1
rsLink.MoveNext
Wend

' reset the cursor to the beginning
If (rsLink.CursorType > 0) Then
rsLink.MoveFirst
Else
rsLink.Requery
End If

' set the number of rows displayed on this page
'establecer el número de filas que se muestran en esta página
If (rsLink_numRows < 0 Or rsLink_numRows > rsLink_total) Then
rsLink_numRows = rsLink_total
End If

' set the first and last displayed record
'establecer el primer y el último registro muestra
rsLink_first = 1
rsLink_last = rsLink_first + rsLink_numRows - 1
If (rsLink_first > rsLink_total) Then rsLink_first = rsLink_total
If (rsLink_last > rsLink_total) Then rsLink_last = rsLink_total

End If
%>
<%
' *** Move To Record and Go To Record: declare variables

Set MM_rs = rsLink
MM_rsCount = rsLink_total
MM_size = rsLink_numRows
MM_uniqueCol = ""
MM_paramName = ""
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName <> "") Then
MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
End If
%>
<%
' *** Move To Record: handle 'index' or 'offset' parameter

if (Not MM_paramIsDefined And MM_rsCount <> 0) then

' use index parameter if defined, otherwise use offset parameter
r = Request.QueryString("index")
If r = "" Then r = Request.QueryString("offset")
If r <> "" Then MM_offset = Int(r)

' if we have a record count, check if we are past the end of the recordset **si tenemos un número de registros, compruebe si estamos más allá del final del conjunto de registros
If (MM_rsCount <> -1) Then
If (MM_offset >= MM_rsCount Or MM_offset = -1) Then ' past end or move last
If ((MM_rsCount Mod MM_size) > 0) Then ' last page not a full repeat region
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' move the cursor to the selected record
i = 0
While ((Not MM_rs.EOF) And (i < MM_offset Or MM_offset = -1))
MM_rs.MoveNext
i = i + 1
Wend
If (MM_rs.EOF) Then MM_offset = i ' set MM_offset to the last possible record

End If
%>
<%
' *** Move To Record: if we dont know the record count, check the display range

If (MM_rsCount = -1) Then

' walk to the end of the display range for this page
i = MM_offset
While (Not MM_rs.EOF And (MM_size < 0 Or i < MM_offset + MM_size))
MM_rs.MoveNext
i = i + 1
Wend

' if we walked off the end of the recordset, set MM_rsCount and MM_size
If (MM_rs.EOF) Then
MM_rsCount = i
If (MM_size < 0 Or MM_size > MM_rsCount) Then MM_size = MM_rsCount
End If

' if we walked off the end, set the offset based on page size
If (MM_rs.EOF And Not MM_paramIsDefined) Then
If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then
If ((MM_rsCount Mod MM_size) > 0) Then
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If
  #2 (permalink)  
Antiguo 20/01/2010, 06:58
 
Fecha de Ingreso: diciembre-2009
Mensajes: 85
Antigüedad: 14 años, 4 meses
Puntos: 0
ayuda con paginación parte 2

este es el resto de mi codigo
*********************

' reset the cursor to the beginning
If (MM_rs.CursorType > 0) Then
MM_rs.MoveFirst
Else
MM_rs.Requery
End If

' move the cursor to the selected record
i = 0
While (Not MM_rs.EOF And i < MM_offset)
MM_rs.MoveNext
i = i + 1
Wend
End If
%>
<%
' *** Move To Record: update recordset stats

' set the first and last displayed record
rsLink_first = MM_offset + 1
rsLink_last = MM_offset + MM_size
If (MM_rsCount <> -1) Then
If (rsLink_first > MM_rsCount) Then rsLink_first = MM_rsCount
If (rsLink_last > MM_rsCount) Then rsLink_last = MM_rsCount
End If

' set the boolean used by hide region to check if we are on the last record
MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then MM_removeList = MM_removeList & "&" & MM_paramName & "="
MM_keepURL="":MM_keepForm="":MM_keepBoth="":MM_kee pNone=""

' add the URL parameters to the MM_keepURL string
For Each Item In Request.QueryString
NextItem = "&" & Item & "="
If (InStr(1,MM_removeList,NextItem,1) = 0) Then
MM_keepURL = MM_keepURL & NextItem & Server.URLencode(Request.QueryString(Item))
End If
Next

' add the Form variables to the MM_keepForm string
For Each Item In Request.Form
NextItem = "&" & Item & "="
If (InStr(1,MM_removeList,NextItem,1) = 0) Then
MM_keepForm = MM_keepForm & NextItem & Server.URLencode(Request.Form(Item))
End If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
if (MM_keepBoth <> "") Then MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
if (MM_keepURL <> "") Then MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
if (MM_keepForm <> "") Then MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%>
<%
' *** Move To Record: set the strings for the first, last, next, and previous links

MM_keepMove = MM_keepBoth
MM_moveParam = "index"

' if the page has a repeated region, remove 'offset' from the maintained parameters
If (MM_size > 0) Then
MM_moveParam = "offset"
If (MM_keepMove <> "") Then
params = Split(MM_keepMove, "&")
MM_keepMove = ""
For i = 0 To UBound(params)
nextItem = Left(params(i), InStr(params(i),"=") - 1)
If (StrComp(nextItem,MM_moveParam,1) <> 0) Then
MM_keepMove = MM_keepMove & "&" & params(i)
End If
Next
If (MM_keepMove <> "") Then
MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)
End If
End If
End If

' set the strings for the move to links
If (MM_keepMove <> "") Then MM_keepMove = MM_keepMove & "&"
urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="
MM_moveFirst = urlStr & "0"
MM_moveLast = urlStr & "-1"
MM_moveNext = urlStr & Cstr(MM_offset + MM_size)
prev = MM_offset - MM_size
If (prev < 0) Then prev = 0
MM_movePrev = urlStr & Cstr(prev)
%>
<div style="height: 20px;"></div>
<%
While ((Repeat2__numRows <> 0) AND (NOT rsLink.EOF))
%>
<%
Dim strLinknum, strDescrip
strLinknum = rsLink("LINK_ID")
strDescrip = rsLink("LINK_DESC")
%>
<div class="dv6">
<div class="votcont"><div style="padding-top: 20px; text-align: center;"><span class="voteres" id="vot<%=(rsLink.Fields.Item("LINK_ID").Value)%>" ><%=(rsLink.Fields.Item("NO_RATES").Value)%></span></div><div class="votbot"><span class="cyel" id="tv<%=(rsLink.Fields.Item("LINK_ID").Value)%>"> <%=FormatNumber((rsLink.Fields.Item("RATING").Valu e), 1, -2, -2, -2) %></span></div></div>
<div class="divlinkname">
<h3><a class="artitle2" title="Visit (<%= (rsLink.Fields.Item("LINK_NAME").Value) %>) link added on (<%=(rsLink.Fields.Item("LINK_DATE").Value)%>)" href="<%=(rsLink.Fields.Item("LINK_URL").Value)%>" target="_blank"><%= (rsLink.Fields.Item("LINK_NAME").Value) %></a></h3></div>
<div class="divsum">


<% Response.Write Left(strDescrip, 250)%>
</div>

<td width="25%" height="115" style="border-style:none; border-width:medium; text-align:center;<font face="Arial" size="2"> <img class=bordeFOT height=110 hspace=10 src="../../dibujos/<%=rs("foto")%>" width=110 align=right vspace=5 border=0></td>



<div class="divopt2">
<span class="conlink6">Rating:<span id="star<%=(rsLink.Fields.Item("LINK_ID").Value)%> "><img src="starimages/<%=FormatNumber((rsLink.Fields.Item("RATING").Valu e), 1, -2, -2, -2) %>.gif" weight="57" height="12" style="vertical-align: middle; border: 0;" alt="<%=(rsLink.Fields.Item("LINK_NAME").Value)%> Link has been Rated <%= FormatNumber((rsLink.Fields.Item("RATING").Value), 1, -2, -2, -2) %> stars"></span></span>
</span><br>
<%
If Request.Cookies("RateSong")("Song" & strLinknum) = "True" Then
%>
<%else%>
<div id="dv<%=(rsLink.Fields.Item("LINK_ID").Value)%>" >
&nbsp;<b><span id="ra<%=(rsLink.Fields.Item("LINK_ID").Value)%>" class="cgr">Vota esta foto</span></b>
<ul class="srating">
<li><a href="javascript:void(0)" onmouseover="document.getElementById('ra<%=(rsLink .Fields.Item("LINK_ID").Value)%>').innerHTML='Poor - 1 estrella'" onmouseout="document.getElementById('ra<%=(rsLink. Fields.Item("LINK_ID").Value)%>').innerHTML='Vote this link'" title="Poor - 1 estrella" class="onestar" onclick="sndRating('<%=(rsLink.Fields.Item("LINK_I D").Value)%>','1');return false">1</a></li>
<li><a href="javascript:void(0)" onmouseover="document.getElementById('ra<%=(rsLink .Fields.Item("LINK_ID").Value)%>').innerHTML='Fair - 2 estrellas'" onmouseout="document.getElementById('ra<%=(rsLink. Fields.Item("LINK_ID").Value)%>').innerHTML='Vote this link'" title="Fair - 2 estrella" class="twostars" onclick="sndRating('<%=(rsLink.Fields.Item("LINK_I D").Value)%>','2');return false">2</a></li>
<li><a href="javascript:void(0)" onmouseover="document.getElementById('ra<%=(rsLink .Fields.Item("LINK_ID").Value)%>').innerHTML='Inte resting - 3 estrellas'" onmouseout="document.getElementById('ra<%=(rsLink. Fields.Item("LINK_ID").Value)%>').innerHTML='Vote this link'" title="Interesting - 3 estrella" class="threestars" onclick="sndRating('<%=(rsLink.Fields.Item("LINK_I D").Value)%>','3');return false">3</a></li>
<li><a href="javascript:void(0)" onmouseover="document.getElementById('ra<%=(rsLink .Fields.Item("LINK_ID").Value)%>').innerHTML='Good - 4 estrellas'" onmouseout="document.getElementById('ra<%=(rsLink. Fields.Item("LINK_ID").Value)%>').innerHTML='Vote this link'" title="Good - 4 estrella" class="fourstars" onclick="sndRating('<%=(rsLink.Fields.Item("LINK_I D").Value)%>','4');return false">4</a></li>
<li><a href="javascript:void(0)" onmouseover="document.getElementById('ra<%=(rsLink .Fields.Item("LINK_ID").Value)%>').innerHTML='Exce llent - 5 estrellas'" onmouseout="document.getElementById('ra<%=(rsLink. Fields.Item("LINK_ID").Value)%>').innerHTML='Vote this link'" title="Excellent - 5 estrella" class="fivestars" onclick="sndRating('<%=(rsLink.Fields.Item("LINK_I D").Value)%>','5');return false">5</a></li>
</ul>

</div>
<%End if%>
</div>
<br>
</div>
<%
Repeat2__index=Repeat2__index+1
Repeat2__numRows=Repeat2__numRows-1
rsLink.MoveNext()
Wend
%>
<br>
</div>
<br>
<br>
<br>
<br>
<%
rsLink.Close()
Set rsLink = Nothing
%>
<p style="text-align: center;"><span class="content2"><a href="http://www.ex-designz.net/directory/default.asp">Live</a></span></p>
<br>
<p style="text-align: center;"><span class="content2"><a href="http://www.banvalor.ws">link</a></span></p>




*******espero me puedan echar una mano
*******gracias
  #3 (permalink)  
Antiguo 20/01/2010, 09:19
Avatar de mc_quake  
Fecha de Ingreso: enero-2006
Ubicación: www.ecocargo.cl
Mensajes: 683
Antigüedad: 18 años, 4 meses
Puntos: 8
Respuesta: ayuda con paginación

Código PHP:
para paginar hechale una vista a este paginador

Dim oConn
rsSQL
Dim PaginaActual
Dim PaginasTotales
Dim TamPagina
Dim CuantosRegistros
TamPagina 
20 'Nº DE REGISTRO POR PAGINA
if Request.Querystring("pagina") = "" then PaginaActual = 1 else PaginaActual = Cint(Request.Querystring("pagina"))
set oConn=Server.CreateObject("ADODB.Connection")
set rs=Server.CreateObject("ADODB.Recordset")
oConn.Open MM_conn_STRING
SQL = "SELECT * FROM TABLA"
rs.PageSize  = TamPagina
rs.CacheSize = TamPagina
rs.Open SQL, oConn, 1, 2
PaginasTotales = rs.PageCount
if PaginaActual < 1 then PaginaActual = 1
if PaginaActual > PaginasTotales then PaginaActual = PaginasTotales
if PaginasTotales=0 then
textotd =  "No se encontraron resultados."
else
rs.AbsolutePage = PaginaActual
textotd =  "Pagina " & PaginaActual & " de " & PaginasTotales
'
========================================================
%>
<
table width="100%" border="0" cellspacing="0" cellpadding="3" id="t1" class="sortable">
<
tr<%= StBarras %>>
</
tr>
<% Do While 
Not Rs.EOF AND CuantosRegistros TamPagina %>
<
tr<%= StColor %>>
</
tr>
<% 
CuantosRegistros=CuantosRegistros 1
Rs
.MoveNext
loop 
%>
</
table>
<%
end if
rs.Close
oConn
.Close
set rs 
nothing
set oConn 
nothing
Response
.Write("<hr size=""1"">  ")
if 
PaginaActual 2 then Response.Write("<A HREF=?pagina="&">Primera Pagina</A> | ") Else Response.Write("<font color=""#CCCCCC"">Primera Pagina</font> | ")
if 
PaginaActual 1 then Response.Write("<A HREF=?pagina="PaginaActual-&">"&TamPagina&" Anteriores</A> | ") Else Response.Write("<font color=""#CCCCCC"">"&TamPagina&" Anteriores</font> | ")
if 
PaginaActual PaginasTotales then Response.Write("<A HREF=?pagina=" PaginaActual+&">"&TamPagina&" Siguientes</A> | ") Else Response.Write("<font color=""#CCCCCC"">"&TamPagina&" Siguientes</font> | ")
if 
PaginaActual PaginasTotales then Response.Write("<A HREF=?pagina=" PaginasTotales &">Ultima Pagina</A>") Else Response.Write("<font color=""#CCCCCC"">Ultima Pagina</font>")
%> 
__________________
Mc_Quake

Para ayudar en lo que se pueda:Zzz:
  #4 (permalink)  
Antiguo 20/01/2010, 13:06
 
Fecha de Ingreso: diciembre-2009
Mensajes: 85
Antigüedad: 14 años, 4 meses
Puntos: 0
Respuesta: ayuda con paginación

Gracias por tu pronta respuesta, disculpa mi ignorancia pero mi pagina esta en asp, y los datos que me pasas son de php, igual me pueden servir??? ha te cuento que aun estoy en pañales en esto de programacion..
  #5 (permalink)  
Antiguo 20/01/2010, 13:48
 
Fecha de Ingreso: agosto-2009
Ubicación: Jalisco,Mexico
Mensajes: 28
Antigüedad: 14 años, 8 meses
Puntos: 2
Respuesta: ayuda con paginación

primero tienes que crear un procedimento almacenado en tu base de datos

Código SQL:
Ver original
  1. CREATE PROCEDURE Paginar(
  2. @inicio INT,
  3. @fin INT)
  4. AS
  5. SELECT * FROM(
  6.     SELECT ROW_NUMBER() OVER(ORDER BY CAT_ID) AS rn,*
  7.     FROM LINKS WHERE LINK_APPROVED=1) AS sub WHERE rn >= @inicio AND rn <= @fin

despues en tu asp vas creando varibles para manipular tus datos
Código ASP:
Ver original
  1. 'numero de registros or pagina
  2.          registros = 10
  3.         'si existe la pagina se toma su valor
  4.         if request.querystring("pagina")<>"" then
  5.          pagina=request.querystring("pagina")      
  6.         else'si no existe se le da el valor de 1
  7.          pagina=1
  8.         end if
  9.         inicio = (pagina - 1) * registros  
  10.     fin = pagina * registros  
  11.    set resultados= rsLink.Execute("Paginar "&inicio&", "&fin&"")
  12.    set result= server.CreateObject("ADODB.RecordSet")
  13.    set result= rsLink.Execute("SELECT * FROM LINKS ")
  14.        
  15.       total_registros = 0
  16.     while not result.eof
  17.       total_registros = total_registros + 1
  18.       result.movenext
  19.     wend
  20.     result.movefirst
  21.    
  22.     total_paginas= total_registros/registros
  23.         if total_paginas >= (CInt(total_paginas)+0.5) then
  24.       total_paginas = CInt(total_paginas) + 1
  25.     else
  26.       total_paginas = CInt(total_paginas)
  27.     end if     
  28.  
  29.  
  30.  'aqui imprimes todas las paginas que hay y en ellas envias el numero de pagina a la que quieres ir
  31.    For i=1 To total_paginas Step 1
  32.     if CInt(pagina)=i then
  33.          response.write(pagina&"|")
  34.     else
  35.          response.write("<a href='estapagina.asp?pagina="&i&"'>"&i&"|</a> ")
  36.      end if  
  37.     next
  38.    
  39.    'despues de eso ya nada mas necesitas haver un while sobre el record set resultados para mostrar tus datos

espero que te sirva
  #6 (permalink)  
Antiguo 20/01/2010, 16:06
Avatar de JuanRAPerez
Colaborador
 
Fecha de Ingreso: octubre-2003
Mensajes: 2.393
Antigüedad: 20 años, 6 meses
Puntos: 27
Respuesta: ayuda con paginación

Cita:
Iniciado por bewmaster Ver Mensaje
Gracias por tu pronta respuesta, disculpa mi ignorancia pero mi pagina esta en asp, y los datos que me pasas son de php, igual me pueden servir??? ha te cuento que aun estoy en pañales en esto de programacion..
lo que te postearon es ASP no en PHP

pruebalo
busca en este foro hay muy buenos ejemplos con ese codigo de paginacion

suerte
__________________
JuanRa Pérez
San Salvador, El Salvador

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:33.