[Resolvido] Problema paginação + mysql
Olá amigos!
Estou tentando fazer uma paginação ASP+Mysql porém nada que eu faço nela dá certo.
<%
pesquisa = Request.QueryString("busca")
on error resume next
set adoConn = Server.CreateObject("ADODB.Connection")
set adoRS = Server.CreateObject("ADODB.Recordset")
adoConn.Open "Driver=MySQL ODBC 3.51 Driver; Server=localhost; Database=pecas; Uid=caioaudax; Pwd=export;"
SET adoRS.ActiveConnection = adoConn
set adoRS3 = Server.CreateObject("ADODB.Recordset")
SET adoRS3.ActiveConnection = adoConn
sql2 = "SELECT COUNT(*) as Descricao FROM Fun007 "
'sql2 = sql2 & "WHERE (uCase(Descricao)) LIKE '%"&pesquisa&"%'"
Set adoRS3 = adoConn.Execute(sql2)
adoRS3.Open
pagina = request.ServerVariables("SCRIPT_NAME")
'numero de registros por pagina...
pageSize = 10
if(len(Request.QueryString("p")) = 0 )then
paginaAtual = 1
else paginaAtual = CInt(Request.QueryString("p"))
end if
recordCount = Cint(adoRS3("Descricao"))
'calculamos o numero de paginas...
pageCount = Clng(recordCount / pageSize)
if pageCount < 1 then
pageCount = 1
end if
adoRS3.Close
Flag1 = INT(paginaAtual / pagesize)
PI = INT(Flag1 * pagesize)
if PI = 0 then
PI = 1
end if
PF = PI + pagesize - 1
str = "SELECT * FROM Fun007 "
'str = str & "WHERE (uCase(Descricao)) LIKE '%"&pesquisa&"%'"
str = str & " LIMIT " & (paginaAtual - 1) * pageSize & " , " & pageSizeset
Set adoRS = adoConn.Execute(str)
adoRS.Open
%>
<p><table width="487" border="0" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="tabela_produtos" id="tabela_produtos">
<tr>
<td background="layout/fundotabela.gif"><span class="style3"> Código</span></td>
<td background="layout/fundotabela.gif"><span class="style3"> N° Original</span></td>
<td background="layout/fundotabela.gif"><span class="style3"> Descrição</span></td>
<td background="layout/fundotabela.gif"><span class="style3"> Opções</span></td>
</tr>
<%
do while not adoRS.eof%>
<tr>
<td width="51" valign="top" bgcolor="#E5E5E5"> <%=adoRS("Fun007")%></td>
<td width="75" valign="top" bgcolor="#E5E5E5" style="margin-bottom:-10px;"> <%
ref = ""
referencia = adoRS("Fun007")
set adoRS1 = Server.CreateObject("ADODB.Recordset")
SET adoRS1.ActiveConnection = adoConn
adoRS1.Open
str1 = "SELECT * FROM exp003 WHERE Fun007 LIKE " & referencia
Set adoRS1 = adoConn.Execute(str1)
If adoRS1.EOF or adoRS1.BOF Then
Response.Write ""
Else
do while not adoRS1.EOF
ref = ref & adoRS1("Referencia_OEM") & "<br/> "
adoRS1.MoveNext
Loop
End if
ref1 = left(ref,(len(ref)-11))
response.Write ref1
%></td><td width="269" valign="top" bgcolor="#E5E5E5"><%=adoRS("Descricao")%></td>
<td width="71" valign="top" bgcolor="#E5E5E5"> </td>
</tr>
<%adoRS.MoveNext()
loop
adoRS.Close
set adoRS = nothing
adoConn.Close
set adoConn = nothing
%>
</table>
<%
Response.Write ("<B><strong> Página " & paginaAtual & " de " & pagecount & " </strong></B><br>")
' cria os links de pagians...
if CInt(paginaAtual) > 1 then
Response.Write "<a href='"&pagina&"?p=1'>Primeira</a> "
Else
Response.Write "<font color=""#ADADAD"">Primeira</font> "
end if
if CInt(paginaAtual) > 1 then
Response.Write "<a href='"&pagina&"?p=" & paginaAtual - 1 &"'>Anterior</a> "
Else
Response.Write "<font color='#666666'>Anterior</font> "
end if
for i=1 to pageCount
Response.Write("<a href='"&pagina&"?p=" & i & "'>" & i & "</a> ")
next
if (CInt(paginaAtual) < pagecount) then
if CInt(PF) <> pagecount then
Response.Write "<a href='"&pagina&"?p=" & paginaAtual+1 & "'>Próxima</a> "
end if
Else
Response.Write "<font color=""#ADADAD"">Próxima</font> "
end if
if (CInt(paginaAtual) <> pagecount) then
if CInt(PF) <> pagecount then
Response.Write "<a href='"&pagina&"?p=" & pagecount & "'>Última</a> "
end if
Else
Response.Write "<font color=""#ADADAD"">Última</font> "
end if
%>
Tem hora que ela fica tentando carregar e não consegue e tem hora que ela simplesmente mostra os números da página mas nenhum resultado.
Agradeço muito pela força!
Discussão (5)
Carregando comentários...