..:: MX Studio Fóruns ::..: [Resolvido]Problema com paginação com filtro - ..:: MX Studio Fóruns ::..

Jump to content

Publicidade




ATENÇÃO

Para evitar posts desnecessários e que não influam para o andamento e desenvolvimento do fórum, clique aqui e leia todas as regras.
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Resolvido]Problema com paginação com filtro

#1 User is offline   Bruno Ortiz 

  • Group: Membros
  • Posts: 8
  • Joined: 02-January 08

Posted 09 April 2010 - 10:57 AM

Fala pessoal beleza?

Estou com um problema de paginação, estou tentando fazer um relatório de paginação com um filtro pelo nome do usuário.
No caso que seja impresso na tela apenas o que é do usuário escolhido.

Estou utilizando a linha:
sql = "SELECT COUNT(*) AS total from bd_pedidos WHERE usuario ='rotaene'"
Com ela, sai como resultado apenas 1 página, porém não com os resultados que escolhi.

quando uso o select assim:
sql = "SELECT COUNT(*) AS total from bd_pedidos"
São impressa 4 páginas (que são todos os resultados)

Vi que realmente está rolando um select, mais não entendi pq não deu certo dele filtrar os resultados que realmente quero, que deveria ser em torno de 4 registro.

Segue o código abaixo que estou utilizando.
O que pode ser?




CÓDIGO
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex,nofollow">
<!--#include file="titPadrao.html"-->

<link rel="stylesheet" type="text/css" href="formatacao.css"  media="screen" />



<style type="text/css">
<!--
#esquerda {
    text-align: left;
}

.fonte {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    text-transform: capitalize;
    color: #333;    
}
.fonte2 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    text-transform: capitalize;
    color: #333;    
}
tr {
    text-align: center;
    border: 1px solid #000;    
}
-->
</style>
</head>


<body>


<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="25%"><p class="alignLogo"><img src="http://www.lagrotta.com.br/imagens/logo_final.png" /></p></td>
        <td width="75%"><p class="alignSaudacao"><% '=rs("contato")%>, <br />
          seja bem vindo(a).</p>
          <p class="alignLogout">Para sair do sistema <a href="logout.asp">clique aqui</a></p></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><img src="imagens/barra_topo.png" /></td>
  </tr>
  <tr>
    <td>
<!--#Include File="arquivo_de_conexao.asp" -->

<%
Call AbreConn()
'pega a pagina atual
pagina = request.ServerVariables("SCRIPT_NAME")

'numero de registros por pagina...

pageSize = 25
if(len(Request.QueryString("p")) = 0 )then  
paginaAtual = 1
else  
paginaAtual = CInt(Request.QueryString("p"))
end if

' conta o numero de registros...
sql = "SELECT COUNT(*) AS total from bd_pedidos WHERE usuario ='rotaene'"

set rs = conn.execute(sql)


'total de registros
recordCount = Cint(rs("total"))

'calculamos o numero de paginas...

pageCount = Clng(recordCount / pageSize)
If pageCount < 1 then
pageCount = 1
end if

rs.Close()

Flag1 = INT(paginaAtual / pagesize)

PI = INT(Flag1 * pagesize)

IF PI = 0 THEN
PI = 1
END IF
PF = PI + pagesize - 1

' selecionamos os registros...

sql = "SELECT * FROM bd_pedidos LIMIT " & (paginaAtual - 1) * pageSize & " , " & pageSize
set rs = conn.execute(sql)  

response.write "<table width=100% height=10 border=1 align=left>"      
response.write "<tr class=itemForm>"
    response.write "<td>Nº Pedido</td>"
    response.write "<td>Data</td>"
    response.write "<td>CNPJ</td>"
    response.write "<td>Cliente</td>"
    response.write "<td>Valor</td>"
    response.write "<td>Prazo Pagamento</td>"
    response.write "<td>Transportadora</td>"
    response.write "<td>Comentários</td>"
    response.write "</tr>"
do while not rs.eof
' aqui entra o q você quer exibir

    

response.write "<tr class=border>"
Response.Write "<td width=30 bgcolor=#FFFFFF class=fonte2>" & rs("nuPedido")&"</span></td>"
Response.Write "<td width=40 bgcolor=#FFFFFF class=fonte2>" & rs("dtPedido")&"</span></td>"
Response.Write "<td width=100 bgcolor=#FFFFFF class=fonte2>" & rs("nuCnpj")&"</span></td>"
Response.Write "<td width=100 bgcolor=#FFFFFF class=fonte2>" & rs("nmCliente")&"</span></td>"
Response.Write "<td width=30 bgcolor=#FFFFFF class=fonte2>" & rs("valor")&"</span></td>"
Response.Write "<td width=147 bgcolor=#FFFFFF class=fonte2>" & rs("dtFaturamento")&"</span></td>"
Response.Write "<td width=100 bgcolor=#FFFFFF class=fonte2>" & rs("nmTransportadora")&"</span></td>"
Response.Write "<td width=237 bgcolor=#FFFFFF class=fonte2>" & rs("obs")&"</span></td>"
rs.MoveNext()
loop
response.write "</table><br /><br /><br /><br /><br />"
rs.Close()
set rs = nothing
Call FechaConn()


set conn = nothing
Response.Write("<br>")
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  
%>
</body>
</html>

This post has been edited by xanburzum: 09 April 2010 - 11:24 AM
Reason for edit: Adicionado BBcode

0

#2 User is offline   xanburzum 

  • Group: Administrador
  • Posts: 2077
  • Joined: 04-November 08

Posted 09 April 2010 - 11:36 AM

existem alguns ótimos exmplosdá um response.write na string SQL, para ver o k esta sendo passado
response.write(SQL)
response.end()
0

#3 User is offline   Bruno Ortiz 

  • Group: Membros
  • Posts: 8
  • Joined: 02-January 08

Posted 09 April 2010 - 11:48 AM

Ele retornou:

SELECT COUNT(*) AS total from bd_pedidos WHERE usuario ='rotaene'
0

#4 User is offline   xanburzum 

  • Group: Administrador
  • Posts: 2077
  • Joined: 04-November 08

Posted 09 April 2010 - 12:18 PM

verifique se o tipo de dados esta correto,
dependendo da situacaun melhor usar um contatdor normal ou a clausula count do SQL, pois se o seu bd for muito grande o recordcount do objeto recordset para apresentar queda de desempenho
e para usar o RecordCount , seu cursortype tem k ser recordset.CursorType = 3 (AdOpenDynamic)

exemplo:
CÓDIGO
<%
DIM mySQL, objRS
mySQL = "SELECT * FROM myTable"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn

' Count how many records exist
DIM iRecordCount
iRecordCount = 0
DO WHILE NOT objRS.EOF
iRecordCount = iRecordCount + 1
objRS.MoveNext
Loop

' Display result
Response.Write "(" & iRecordCount & ")"

objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>


SQL COUNT

CÓDIGO
<!--#INCLUDE VIRTUAL="/includes/connection.asp" -->

<%
DIM mySQL, objRS
mySQL = "SELECT Count(*) AS intTotal FROM myTable"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open recSQL, objConn

' Display result
Response.Write objRS("intTotal")

objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>

0

#5 User is offline   Bruno Ortiz 

  • Group: Membros
  • Posts: 8
  • Joined: 02-January 08

Posted 09 April 2010 - 12:28 PM

É que não manjo mto cara, to aprendendo e tals.
Como poderia adaptar isso ao meu código?
0

#6 User is offline   xanburzum 

  • Group: Administrador
  • Posts: 2077
  • Joined: 04-November 08

Posted 09 April 2010 - 02:01 PM

insira ele , imediatamente após o Set objRS = Server.CreateObject("ADODB.Recordset")
0

#7 User is offline   Bruno Ortiz 

  • Group: Membros
  • Posts: 8
  • Joined: 02-January 08

Posted 09 April 2010 - 02:59 PM

não consegui entender... como ficaria o código que postei no inicio?
0

#8 User is offline   Bruno Ortiz 

  • Group: Membros
  • Posts: 8
  • Joined: 02-January 08

Posted 09 April 2010 - 04:25 PM

eu consegui selecionar os dados que eu queria, porém perdi a paginação....

Seguinte código:

Mano, vcs sabem se tem como eu fazer as 2 coisas juntas?
tem como eu misturar esse sql e o sql2 no record set? se der já elvis


sql = "SELECT COUNT(*) AS total from bd_pedidos"
sql2 = "SELECT * From bd_pedidos WHERE usuario= 'rotaene'"


sql = "SELECT * FROM bd_pedidos LIMIT " & (paginaAtual - 1) * pageSize & " , " & pageSize

set rs = conn.execute(sql)
set rs = conn.execute(sql2)
0

#9 User is offline   ursolouco 

  • Group: Membros
  • Posts: 9
  • Joined: 04-March 04

Posted 09 April 2010 - 04:42 PM

CÓDIGO
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex,nofollow">
<!--#include file="titPadrao.html"-->
<link rel="stylesheet" type="text/css" href="formatacao.css"  media="screen" />
<style type="text/css">
<!--
#esquerda {
    text-align: left;
}
.fonte {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    text-transform: capitalize;
    color: #333;
}
.fonte2 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    text-transform: capitalize;
    color: #333;
}
tr {
    text-align: center;
    border: 1px solid #000;
}
-->
</style>
</head>
<body>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="25%"><p class="alignLogo"><img src="http://www.lagrotta.com.br/imagens/logo_final.png" /></p>
                    </td>
                    <td width="75%"><p class="alignSaudacao">
                            <% '=rs("contato")%>
                            , <br />
                            seja bem vindo(a).</p>
                        <p class="alignLogout">Para
                            sair do sistema <a href="logout.asp">clique aqui</a></p>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td><img src="imagens/barra_topo.png" /></td>
    </tr>
    <tr>
        <td>
            <!--#Include File="arquivo_de_conexao.asp" -->
            <%
Call AbreConn()
'pega a pagina atual
pagina = request.ServerVariables("SCRIPT_NAME")
'numero de registros por pagina...
pageSize = 25
p = Request.QueryString("p")
p = CInt(p)

paginaAtual = p

if paginaAtual < 1 then
    paginaAtual = 1
end if

' conta o numero de registros...
sql           = "  SELECT COUNT(*) AS total from bd_pedidos "
set rs      = conn.execute(sql)

'total de registros
recordCount = Cint(rs("total"))

'calculamos o numero de paginas...
pageCount = Clng(recordCount / pageSize)

If pageCount < 1 then
    pageCount = 1
end if

Flag1 = INT(paginaAtual / pagesize)
PI = INT(Flag1 * pagesize)
IF PI = 0 THEN
    PI = 1
END IF

PF = PI + pagesize - 1

' selecionamos os registros...
sql = "SELECT * FROM bd_pedidos LIMIT " & (paginaAtual - 1) * pageSize & " , " & pageSize
set rs = conn.execute(sql)
response.write "<table width=100% height=10 border=1 align=left>"
response.write "<tr class=itemForm>"
    response.write "<td>Nº Pedido</td>"
    response.write "<td>Data</td>"
    response.write "<td>CNPJ</td>"
    response.write "<td>Cliente</td>"
    response.write "<td>Valor</td>"
    response.write "<td>Prazo Pagamento</td>"
    response.write "<td>Transportadora</td>"
    response.write "<td>Comentários</td>"
    response.write "</tr>"
do while not rs.eof
' aqui entra o q você quer exibir
response.write "<tr class=border>"
Response.Write "<td width=30 bgcolor=#FFFFFF class=fonte2>" & rs("nuPedido")&"</span></td>"
Response.Write "<td width=40 bgcolor=#FFFFFF class=fonte2>" & rs("dtPedido")&"</span></td>"
Response.Write "<td width=100 bgcolor=#FFFFFF class=fonte2>" & rs("nuCnpj")&"</span></td>"
Response.Write "<td width=100 bgcolor=#FFFFFF class=fonte2>" & rs("nmCliente")&"</span></td>"
Response.Write "<td width=30 bgcolor=#FFFFFF class=fonte2>" & rs("valor")&"</span></td>"
Response.Write "<td width=147 bgcolor=#FFFFFF class=fonte2>" & rs("dtFaturamento")&"</span></td>"
Response.Write "<td width=100 bgcolor=#FFFFFF class=fonte2>" & rs("nmTransportadora")&"</span></td>"
Response.Write "<td width=237 bgcolor=#FFFFFF class=fonte2>" & rs("obs")&"</span></td>"
rs.MoveNext()
loop
response.write "</table><br /><br /><br /><br /><br />"

set rs = nothing

Call FechaConn()

set conn = nothing

Response.Write("<br>")
Response.Write ("<B><strong> Página " & paginaAtual & " de " & pagecount & " </strong></B><br>")

' cria os links de paginas...
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
%>
        </td>
    </tr>
</table>
</body>
</html>

0

#10 User is offline   xanburzum 

  • Group: Administrador
  • Posts: 2077
  • Joined: 04-November 08

Posted 09 April 2010 - 04:59 PM

olha este exemplo:
CÓDIGO
'crio o rs
  set rs=Server.CreateObject("ADODB.Recordset")
  'crio o SQL
  SQL="SELECT * FROM login Where codigo between "&var1&" AND "&var2&""
  rs.open SQL,conexao,1,3

0

#11 User is offline   Bruno Ortiz 

  • Group: Membros
  • Posts: 8
  • Joined: 02-January 08

Posted 12 April 2010 - 10:42 AM

Valeu xanburzum e ursolouco, deu certo! biggrin.gif
abs
0

#12 User is offline   xanburzum 

  • Group: Administrador
  • Posts: 2077
  • Joined: 04-November 08

Posted 12 April 2010 - 10:44 PM

ok, beleza
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic



Publicidade




1 User(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)