Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

:: kabulozo::

Filtrar consulta

Recommended Posts

Olha eu aqui de novo :D .Bom, é o seguinte, tenho uma pagina no meu site que contem todas as letras do alfabeto e o caractere #, ex:# A B C D E ... ZCriei uma consulta pra que fosse listado só os resultados que tivesse a inicial informada. Só que com o caractere # não to conseguindo, pois quando eu clico nele, ele me retorna todos os registros, sendo que era pra ele retornar os registros que não tem letras de A-Z.Como eu poderia resolver este problema.PS: Uso banco de dados MySQL.Desde já agradeço a todos que colaborarem.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Eu ainda não aprendi a trabalhar com funções :( .

 

O código para listar a consulta segue abaixo.

 

Response.Write("<html>"&vbCrlf&_

   "<head>"&vbCrlf&_

   " <title>"&Application("NomeSite")&" -> Artistas</title>"&vbCrlf&_

   " <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>"&vbCrlf&_

   " <link href='../css/site.css' rel='stylesheet' type='text/css'>"&vbCrlf&_

   "</head>"&vbCrlf&_

   ""&vbCrlf&_

   "<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>")

 

 

str_Inicial = Request.Querystring("letra")

 

int_ResTotal = 20

 

     If Request.QueryString("pagina") = "" Then

    int_Pagina = 1

     Else

    int_Pagina = Request.QueryString("pagina")

     End If

 

    Conecta()  

     Set rs = Server.CreateObject("ADODB.RECORDSET")

    rs.CacheSize = int_ResTotal

rs.CursorLocation = 3

 

     If str_Inicial <> CHR(35) Then

sql = "SELECT "

    sql = sql & " * "

    sql = sql & " FROM "

    sql = sql & " pdlartistas "

    sql = sql & " WHERE "

    sql = sql & " pdlartnom "

    sql = sql & " LIKE "

    sql = sql & " '"&Replace(str_Inicial,"'","''")&"%' "

    sql = sql & " ORDER BY "

    sql = sql & " pdlartnom "

    sql = sql & " ASC "

  Else

sql = "SELECT "

    sql = sql & " * "

    sql = sql & " FROM "

    sql = sql & " pdlartistas "

    sql = sql & " WHERE "

    sql = sql & " pdlartnom "

    sql = sql & " NOT LIKE "

    sql = sql & " '[A-Z]%' "

    sql = sql & " ORDER BY "

    sql = sql & " pdlartnom "

    sql = sql & " ASC "

  End If

rs.Open sql, con

  

     If rs.EOF Then     

   Response.Write(""&_

   "<table width='460' height='18' border='0' align='center' cellpadding='0' cellspacing='0' bgcolor='#C0E725'>"&_

   " <tr>"&_

   "  <td>"&_

   "   <p> <strong>// Listando Artistas/Bandas</strong></p>"&_

   "  </td>"&_

   " </tr>"&_

   "</table>"&_

   "<table width='460' border='0' align='center' cellpadding='0' cellspacing='0' bgcolor='#EFEFEF'>"&_

   " <tr>"&_

   "  <td valign='top'>"&_

   "   <p> </p>"&_

   "   <p align='center'>Não há artista/banda cadastrado(a) com esta inicial.</p>"&_

   "   <p> </p>"&_

   "  </td>"&_

   " </tr>"&_

   "</table>")

     Else

   Response.Write(""&_

   "<table width='460' height='18' border='0' align='center' cellpadding='0' cellspacing='0' bgcolor='#C0E725'>"&_

   " <tr>"&_

   "  <td>"&_

   "   <p> <strong>// Listando Artistas/Bandas</strong></p>"&_

   "  </td>"&_

   " </tr>"&_

   "</table>"&_

   "<table width='460' border='0' align='center' cellpadding='0' cellspacing='0' bgcolor='#EFEFEF'>"&_

   " <tr>"&_

   "  <td valign='top'>"&_

   "   <p> </p>"&_

   "<table width='460' border='0' cellpadding='0' cellspacing='0' class='tdestaque'>"&_

   " <tr>"&_

   "  <td valign='top'>"&_

   "<table width='456' border='0' align='center' cellpadding='0' cellspacing='0'>"&_

   " <tr>"&_

   "  <td>")

 

int_QtdIni = ((int_ResTotal * CInt(int_Pagina)) - int_ResTotal) + 1

int_QtdFin = (int_ResTotal * (CInt(int_Pagina) + 1)) - int_ResTotal

 

  IF int_QtdFin > rs.RecordCount Then

int_QtdFin = rs.RecordCount

  End If

  

  If rs.RecordCount <> 1 Then

   Response.Write(""&_

   "   <p class='pdestaque'>Foram encontrados <font color='#666666'><strong>"&rs.RecordCount&""&_

   "   </strong></font> artistas com a inicial <strong><font color='#666666'>"&str_Inicial&"</font></strong>.</p>")

  Else

   Response.Write(""&_

   "   <p class='pdestaque'>Foi encontrado <font color='#666666'><strong>"&rs.RecordCount&""&_

   "   </strong></font> artista com a inicial <strong><font color='#666666'>"&str_Inicial&"</font></strong>.</p>")

  End If

 

   Response.Write("   <p class='pdestaque'>Exibindo de <strong><font color='#666666'>")

 

  IF rs.RecordCount > 0 Then

   Response.Write(""&_

   ""&int_QtdIni&"</font></strong> até <strong><font color='#666666'>"&int_QtdFin&"")

  End If

  

   Response.Write(""&_

   "   </font></strong> resultados.</p>"&_

   "  </td>"&_

   " </tr>"&_

   "</table>"&_

   "  </td>"&_

   " </tr>"&_

   "</table>"&_

   "<p> </p>")

  

rs.MoveFirst

rs.PageSize = int_ResTotal

int_PagTotal = rs.PageCount

rs.AbsolutePage = int_Pagina

 

   Response.Write(""&_

   "<table width='460' border='0' cellspacing='0' cellpadding='0'>"&_

   " <tr>")

 

cont = 0

cont1 = 1

 

  Do While not rs.EOF AND cont < rs.PageSize

   

   Response.Write(""&_

   "  <td valign='top' width='230'>"&_

   "   <p class='presultados'><strong>.<a href='?secao=Artistas&opcao=Exibir&id_artista="&rs("pdlartid")&"'>"&rs("pdlartnom")&"</a></strong></p>"&_

   "  </td>")

 

  If cont1 = 2 Then

     cont1 = 0

   Response.Write(""&_

   " </tr>"&_

   " <tr>")   

  End If

 

cont1 = cont1 + 1

cont = cont + 1

rs.MoveNext

  Loop

   

   Response.Write(""&_

   " </tr>"&_

   "</table>"&_

   "   <p> </p>"&_

   "   <p align='center'>")

 

  If int_Pagina > 1 Then

   Response.Write(""&_

   "   <a href='?secao=Artistas&opcao=Lista&letra="&str_Inicial&"&pagina="&int_Pagina-1&"'><img border='0' src='img/fg_bt_voltar.gif' alt='Voltar'></a> "&_

   "  <p> </p>")

  End If

 

  If CInt(int_Pagina) <> CInt(int_PagTotal) Then  

   Response.Write(""&_

   "   <a href='?secao=Artistas&opcao=Lista&letra="&str_Inicial&"&pagina="&int_Pagina+1&"'><img border='0' src='img/fg_bt_avancar.gif' alt='Avançar'></a> "&_

   "  <p> </p>")

  End If

 

   Response.Write(""&_

   "  </p>"&_

   "  </td>"&_

   " </tr>"&_

   "</table>")

  End If

 

rs.Close

  Set rs = Nothing

Desconecta()

  Set cont1 = Nothing

  Set cont = Nothing

  Set int_PagTotal = Nothing

  Set int_QtdFin = Nothing

  Set int_QtdIni = Nothing

  Set con = Nothing

  Set sql = Nothing

  Set int_Pagina = Nothing

  Set int_ResTotal = Nothing

 

   Response.Write("</body>"&vbCrlf&_

                  "</html>")

PS: A parte em negrito, foi um teste que eu tentei, quando li um outro topico, mas isso so funciona no SQL Server.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.