Ir para conteúdo

Arquivado

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

cintiadel

Select com Filtro

Recommended Posts

Nesse primeiro eu preciso que ao selecionar o nome da cidade no dropdown, juntamente com o radio button mais votados ou melhores cozinhas ele filtre de acordo com a cidade os 50 restaurantes melhores colocados pela posição no caso de mais votados selecionado, e no caso de melhores cozinhas as 5 melhores.

Não está dando erro, mas quando eu escolho a cidade ele me traz somente o filtro posicaoVotado<=50

 

myselLoc1 = "select * from Local where posicaoVotado<=50"
if request("cidade") <> "" then 
   myselLoc1 = myselLoc1 & "and cidLoc=" & request("cidade")
end if 
if request("escolha") = "mais" then 
   myselLoc1 = myselLoc1 & "and escolha=" & request("mais")
   response.Redirect("MaisVotadosLista.asp")
end if 
if request("escolha") = "cozinha" then 
   myselLoc1 = myselLoc1 & "and escolha=" & request("cozinha")
   response.Redirect("CatCozinhas.asp")
end if 
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Teste isso:

myselLoc1 = "select * from Local where posicaoVotado<=50"
if request("cidade") <> "" then
   myselLoc1 = myselLoc1 & " and cidLoc=" & request("cidade")
end if
if request("escolha") = "mais" then
   myselLoc1 = myselLoc1 & " and escolha=" & request("mais")
   Response.Write myselLoc1
   Response.End
   response.Redirect("MaisVotadosLista.asp")
end if
if request("escolha") = "cozinha" then
   myselLoc1 = myselLoc1 & " and escolha=" & request("cozinha")
   Response.Write myselLoc1
   Response.End
   response.Redirect("CatCozinhas.asp")
end if
%>
Veja a query no browse e verifique se está correto.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Teste isso:

myselLoc1 = "select * from Local where posicaoVotado<=50"
if request("cidade") <> "" then
   myselLoc1 = myselLoc1 & " and cidLoc=" & request("cidade")
end if
if request("escolha") = "mais" then
   myselLoc1 = myselLoc1 & " and escolha=" & request("mais")
   Response.Write myselLoc1
   Response.End
   response.Redirect("MaisVotadosLista.asp")
end if
if request("escolha") = "cozinha" then
   myselLoc1 = myselLoc1 & " and escolha=" & request("cozinha")
   Response.Write myselLoc1
   Response.End
   response.Redirect("CatCozinhas.asp")
end if
%>
Veja a query no browse e verifique se está correto.

Desse jeito que você passou apareceu isso no browse:

select * from Local where posicaoVotado<=50 and cidLoc=São Paulo and escolha=

Pelo visto ele não está pegando o valor da escolha agora

Compartilhar este post


Link para o post
Compartilhar em outros sites

E assim:

myselLoc1 = "select * from Local where posicaoVotado<=50"
if request("cidade") <> "" then
   myselLoc1 = myselLoc1 & " and cidLoc=" & request("cidade")
end if
if request("escolha") = "mais" then
   myselLoc1 = myselLoc1 & " and escolha=" & request("escolha")
   Response.Write myselLoc1
   Response.End
   response.Redirect("MaisVotadosLista.asp")
end if
if request("escolha") = "cozinha" then
   myselLoc1 = myselLoc1 & " and escolha=" & request("escolha")
   Response.Write myselLoc1
   Response.End
   response.Redirect("CatCozinhas.asp")
end if
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

E assim:

myselLoc1 = "select * from Local where posicaoVotado<=50"
if request("cidade") <> "" then
   myselLoc1 = myselLoc1 & " and cidLoc=" & request("cidade")
end if
if request("escolha") = "mais" then
   myselLoc1 = myselLoc1 & " and escolha=" & request("escolha")
   Response.Write myselLoc1
   Response.End
   response.Redirect("MaisVotadosLista.asp")
end if
if request("escolha") = "cozinha" then
   myselLoc1 = myselLoc1 & " and escolha=" & request("escolha")
   Response.Write myselLoc1
   Response.End
   response.Redirect("CatCozinhas.asp")
end if
%>

ainda sim ele não está exibindo de acordo com a cidade que eu seleciono? só está exibindo de acordo com a posicao

Compartilhar este post


Link para o post
Compartilhar em outros sites

A query está sendo exibida corretamente?

aparentemente sim:

select * from Local where posicaoVotado<=50 and cidLoc=São Paulo and escolha=mais

Compartilhar este post


Link para o post
Compartilhar em outros sites

nos campos texto coloque aspas simples

Compartilhar este post


Link para o post
Compartilhar em outros sites

o que importa é o que esta no DB se for do tipo texto aspas simples

Compartilhar este post


Link para o post
Compartilhar em outros sites

o que importa é o que esta no DB se for do tipo texto aspas simples

Onde? Pq se eu troco " por ' ele coloca como comentario?

 

<%
myselLoc1 = "select * from Local where posicaoVotado<=50"
if request("cidade") <> "" then
   myselLoc1 = myselLoc1 & " and cidLoc=" & request("cidade")
end if
if request("escolha") = "mais" then
   myselLoc1 = myselLoc1 & " and escolha=" & request("escolha")
   Response.Write myselLoc1
   Response.End
   response.Redirect("MaisVotadosLista.asp")
end if
if request("escolha") = "cozinha" then
   myselLoc1 = myselLoc1 & " and escolha=" & request("escolha")
   Response.Write myselLoc1
   Response.End
   response.Redirect("CatCozinhas.asp")
end if
'db.execute myselLoc1
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Assim:

<%
myselLoc1 = "select * from Local where posicaoVotado<=50"
if request("cidade") <> "" then
   myselLoc1 = myselLoc1 & " and cidLoc='" & request("cidade") & "'"
end if
if request("escolha") = "mais" then
   myselLoc1 = myselLoc1 & " and escolha='" & request("escolha") & "'"
   Response.Write myselLoc1
   Response.End
   response.Redirect("MaisVotadosLista.asp")
end if
if request("escolha") = "cozinha" then
   myselLoc1 = myselLoc1 & " and escolha='" & request("escolha") & "'"
   Response.Write myselLoc1
   Response.End
   response.Redirect("CatCozinhas.asp")
end if
'db.execute myselLoc1
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

nao é para trocar nada

 

é para acrescentar as aspas simples

 

exemplo aqui

 

em vez de

 

myselLoc1 = myselLoc1 & " and escolha=" & request("escolha")

faça

 

myselLoc1 = myselLoc1 & " and escolha='" & request("escolha") & "'"

notou que adicionei aspas simples antes e depois do valor?

Compartilhar este post


Link para o post
Compartilhar em outros sites

nao é para trocar nada

 

é para acrescentar as aspas simples

 

exemplo aqui

 

em vez de

 

myselLoc1 = myselLoc1 & " and escolha=" & request("escolha")

faça

 

myselLoc1 = myselLoc1 & " and escolha='" & request("escolha") & "'"

notou que adicionei aspas simples antes e depois do valor?

 

Continua não filtrando pela cidade

<%
myselLoc1 = "select * from Local where posicaoVotado<=50"
if request("cidade") <> "" then
   myselLoc1 = myselLoc1 & " and cidLoc='" & request("cidade")
   
end if
if request("escolha") = "mais" then
   myselLoc1 = myselLoc1 & " and escolha='" & request("escolha") & "'"
   'Response.Write myselLoc1
   'Response.End
   response.Redirect("MaisVotadosLista.asp")
end if
if request("escolha") = "cozinha" then
   myselLoc1 = myselLoc1 & " and escolha='" & request("escolha")
   'Response.Write myselLoc1
   'Response.End
   response.Redirect("CatCozinhas.asp")
end if
'db.execute myselLoc1
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Assim:

<%
myselLoc1 = "select * from Local where posicaoVotado<=50"
if request("cidade") <> "" then
myselLoc1 = myselLoc1 & " and cidLoc='" & request("cidade") & "'"

end if
if request("escolha") = "mais" then
myselLoc1 = myselLoc1 & " and escolha='" & request("escolha") & "'"
'Response.Write myselLoc1
'Response.End
response.Redirect("MaisVotadosLista.asp")
end if
if request("escolha") = "cozinha" then
myselLoc1 = myselLoc1 & " and escolha='" & request("escolha") & "'"
'Response.Write myselLoc1
'Response.End
response.Redirect("CatCozinhas.asp")
end if
'db.execute myselLoc1
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Assim:

<%
myselLoc1 = "select * from Local where posicaoVotado<=50"
if request("cidade") <> "" then
myselLoc1 = myselLoc1 & " and cidLoc='" & request("cidade") & "'"

end if
if request("escolha") = "mais" then
myselLoc1 = myselLoc1 & " and escolha='" & request("escolha") & "'"
'Response.Write myselLoc1
'Response.End
response.Redirect("MaisVotadosLista.asp")
end if
if request("escolha") = "cozinha" then
myselLoc1 = myselLoc1 & " and escolha='" & request("escolha") & "'"
'Response.Write myselLoc1
'Response.End
response.Redirect("CatCozinhas.asp")
end if
'db.execute myselLoc1
%>

 

nada continua sem filtrar pela cidade

Compartilhar este post


Link para o post
Compartilhar em outros sites

imprime a sql na tela para ver como esta agora

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.