Ir para conteúdo

POWERED BY:

Arquivado

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

Boris

Agrupamento de valores

Recommended Posts

Boa Tarde Galera fazendo uma busca porem estou com alguns problemas...VAMOS LÁ...tenho uma tabela com varios campos..TABELA: ContatoCAMPOS: Nome - Endereco - Bairro - Telefone - E-mailNo momento que vou fazer uma busca eu tenho os seguintes campos Bairro NomeO campo Bairro é um combo que lista todos os bairros que estão cadastrado na TABELA : Contato CAMPO : Bairro PROBLEMA:Se tiver um bairro que se repete em outros contatos ele repete no combo e eu gostaria que ele não se repetisseSegue logo abaixo o codigo:

<!--#include file="cn.asp"--><html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Procura apenas nesta página</title><style type="text/css"><!--.texto8bold {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; font-weight: bold; color: #3F68AD; text-decoration: none}--></style></head><body><form method="post" action="search.asp"><div style="border:1px solid black;padding:4px;width:237px;height:63px"><table width="707" border="0" cellpadding="0"><tr><td width="28"> </td> <td width="177"> </td> <td width="230"><span class="texto8bold"> Bairro <select name="bairro" class="texto8bold"> <% intConta = 1bairro = "select * from contato where ativo='1'"set bairro_rs = cn.Execute(bairro)if bairro_rs.BOF AND bairro_rs.EOF then%> <option>Sem Bairro</option> <%else while NOT bairro_rs.EOF AND intConta <=5000 intConta = intConta + 1 %> <option> <% response.Write(bairro_rs("bairro"))%> </option> <%bairro_rs.MoveNextWendend ifbairro_rs.Closeset bairro_rs = nothing%> </select> </span></td> <td width="262"><input type="text" name="q" size="25"maxlength="255" value="" /> <input name="submit" type="submit" value="Go" /></td></tr><tr><td height="10" colspan="4" align="center" style="font-size:75%"><input type="checkbox" name="sitesearch"value="sitesearch" checked /> Procura apenas nesta página</td> </tr></table></div></form></body></html>

Alguem pode me ajudar... http://forum.imasters.com.br/public/style_emoticons/default/thumbsup.gif

Compartilhar este post


Link para o post
Compartilhar em outros sites

quando inicia o while, verifica se a variavel X é vazia ou diferente do registro atual, se for diferente monta o combo, no final do if você armazena na variavel X o atual registro do recordset para ser comparado no proximo loop. Porém terá que usar order by bairro. Se estiver selecionando apenas o bairro no sql, utilize a função distinct

Compartilhar este post


Link para o post
Compartilhar em outros sites

Eu tentei fazer mas não estou conseguindo alguem pode me ajudar eis ai o codigo que estou usando...<!--#include file="cn.asp"--><select name="bairro" class="texto8bold"> <% intConta = 1bairro = "select * from imovel where ativo='1'"set bairro_rs = cn.Execute(bairro)if bairro_rs.BOF AND bairro_rs.EOF then%> <option>Sem Bairro</option> <%else while NOT bairro_rs.EOF AND intConta <=5000 intConta = intConta + 1 %> <option> <% response.Write(bairro_rs("bairro"))%> </option> <% bairro_rs.MoveNextWendend ifbairro_rs.Closeset bairro_rs = nothing%></select>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Faz o que o jonathandj falou:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Procura apenas nesta página</title><style type="text/css"></style></head><body><form method="post" action="search.asp"><div style="border:1px solid black;padding:4px;width:237px;height:63px"><table width="707" border="0" cellpadding="0"><tr><td width="28"> </td><td width="177"> </td><td width="230"><span class="texto8bold">Bairro<select name="bairro" class="texto8bold"><%intConta = 1bairro = "select distinct bairro from contato where ativo='1'"set bairro_rs = cn.Execute(bairro)if bairro_rs.BOF AND bairro_rs.EOF then%><option>Sem Bairro</option><%elsewhile NOT bairro_rs.EOF AND intConta <=5000intConta = intConta + 1%><option><% response.Write(bairro_rs("bairro"))%></option><%bairro_rs.MoveNextWendend ifbairro_rs.Closeset bairro_rs = nothing%></select></span></td><td width="262"><input type="text" name="q" size="25"maxlength="255" value="" /><input name="submit" type="submit" value="Go" /></td></tr><tr><td height="10" colspan="4" align="center" style="font-size:75%"><input type="checkbox" name="sitesearch"value="sitesearch" checked />Procura apenas nesta página</td></tr></table></div></form></body></html>
bairro = "select distinct bairro from contato where ativo='1'"

Compartilhar este post


Link para o post
Compartilhar em outros sites

putz deu certo eu estava me confundindo com o distinct pois não conhecia esse comando Valew galera deu certinho....Obrigadão

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.