Ir para conteúdo

POWERED BY:

Arquivado

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

Paulo Beck

Lógica errada

Recommended Posts

Oi galera...bom...estou com um problema...fiz uma página que exibe um resultado de pesquisa...meu critério de seleção utiliza LIKE por isso precisaria listar mais de um registro...mas lista apenas um...o erro deve estar na minha lógica...Aí vai a página:<%@include file="conecta.jsp"%><%@include file="nivel.jsp"%><!--#include file="estilo.inc"--><HTML><HEAD> <TITLE>ACDA - Lista doadores</TITLE> <Base target="_top"></HEAD><BODY BGCOLOR="#FFFFFF" TOPMARGIN="10" RIGHTMARGIN="10"> <IMG BORDER="0" SRC="imagens/acda_logo_nome.jpg" WIDTH="600" HEIGHT="63"><HR> <BR> <CENTER><FONT FACE="Arial" SIZE="4"><B>Lista doadores</B></FONT></CENTER> <BR><% ResultSet rs; int tipo=Integer.parseInt(request.getParameter("tipo")); String sql="SELECT * FROM doadores WHERE "; if(tipo==1) { String codigo=request.getParameter("codigo"); if(codigo==null||codigo.equals("")) codigo="null"; sql+="id_doador="+codigo; } else if(tipo==2) { String nome=request.getParameter("nome"); if(nome==null||nome.equals("")) nome="null"; nome=nome.toUpperCase(); sql+="nome LIKE '%"+nome+"%'"; } else if(tipo==3) { String tel=request.getParameter("tel"); if(tel==null||tel.equals("")) tel="null"; sql+="telefone_resid='"+tel+"' OR telefone_comer='"+tel+"' OR telefone_cel='"+tel+"'"; }rs=stm.executeQuery(sql);int i=0;while(rs.next()){ i=i+1; String pid=rs.getString("id_doador"); String pnome=rs.getString("nome"); String pendereco=rs.getString("endereco"); String pn=rs.getString("n"); String pcomplemento=rs.getString("complemento"); String pbairro=rs.getString("bairro"); String pcidade=rs.getString("cidade"); String pcep=rs.getString("cep"); String puf=rs.getString("uf"); String ptelefone_comer=rs.getString("telefone_comer"); String ptelefone_cel=rs.getString("telefone_cel"); String ptelefone_resid=rs.getString("telefone_resid"); String precado=rs.getString("recado"); String pid_func=rs.getString("id_func"); String pid_status=rs.getString("id_status");%> <TABLE BORDER="0" WIDTH="100%" CELLPADDING="2" CELLSPACING="5" BGCOLOR=#F4F4F4> <TR> <TD ALING="right" BGCOLOR="#F4F4F4" WIDTH="1%"> <span style="Background-color: #F4F4F4"><B> <FONT COLOR="#000080">Códig</FONT></B></span> </TD> <TD ALING="right" BGCOLOR="#F4F4F4" COLSPAN=5> <FONT COLOR="#000000"><%=pid%> </FONT> </TD> </TR> <TR> <TD BGCOLOR="#F4F4F4"> <B><span style="Background-color: #F4F4F4"><FONT COLOR="#000080"> Nome: </FONT></span></B> </TD> <TD BGCOLOR="#F4F4F4" COLSPAN=5><FONT COLOR="#000000"><%=pnome%></FONT> </TR> <TR> <TD BGCOLOR="#F4F4F4"> <B><FONT COLOR="#000080">Endereç</FONT></B> </TD> <TD BGCOLOR="#F4F4F4" COLSPAN=3> <FONT COLOR="#000000"><%=pendereco%> </FONT> </TD> <TD BGCOLOR="#F4F4F4" WIDTH="1%"> <B><FONT COLOR="#000080"> Nº:</FONT></B> </TD> <TD BGCOLOR="#F4F4F4"> <FONT COLOR="#000000"><%=pn%> </TD> </TR> <TR> <TD BGCOLOR="#F4F4F4"> <B><span style="Background-color: #F4F4F4"> <FONT COLOR="#000080">Complement</FONT></span></B> </TD> <TD BGCOLOR="#F4F4F4"><FONT COLOR="#000000"><%=pcomplemento%> </FONT> </TD> <TD BGCOLOR="#F4F4F4" WIDTH="1%"> <B><span style="Background-color: #F4F4F4"> <FONT COLOR="#000080">Bairr</FONT></span></B> </TD> <TD BGCOLOR="#F4F4F4" COLSPAN=3><FONT COLOR="#000000"><%=pbairro%> </FONT> </TD> </TR> <TR> <TD BGCOLOR="#F4F4F4"> <B><span style="Background-color: #F4F4F4"> <FONT COLOR="#000080">Cidade:</FONT></span></B> </TD> <TD BGCOLOR="#F4F4F4"> <FONT COLOR="#000000"><%=pcidade%> </FONT> </TD> <TD BGCOLOR="#F4F4F4"> <B><FONT COLOR="#000080">CEP:</FONT></B></TD> <TD BGCOLOR="#F4F4F4"> <FONT COLOR="#000000"><%=pcep%> </FONT> </TD> <TD BGCOLOR="#F4F4F4"> <B><span style="Background-color: #F4F4F4"> <FONT COLOR="#000080">UF:</FONT></span></B></TD> <TD BGCOLOR="#F4F4F4"> <FONT COLOR="#000000"><%=puf%> </FONT> </TD> </TR> <TR> <TD> <B><FONT COLOR="#000080">Fone Resid.:</FONT></B> </TD> <TD> <FONT COLOR="#000000"><%=ptelefone_resid%></FONT> </TD> <TD> <B><FONT COLOR="#000080">Fone Cel.:</FONT></B> </TD> <TD> <FONT COLOR="#000000"><%=ptelefone_cel%></FONT> </TD> <TD BGCOLOR="#F4F4F4"> <B><FONT COLOR="#000080">Fone Comer.:</FONT></B> </TD> <TD BGCOLOR="#F4F4F4"> <FONT COLOR="#000000"><%=ptelefone_comer%></FONT> </TD> </TR> <TR> <TD BGCOLOR="#F4F4F4"> <B><FONT COLOR="#000080">Contat</FONT></B> </TD> <TD BGCOLOR="#F4F4F4"> <FONT COLOR="#000000"><%=precado%> </FONT> </TD> <TD BGCOLOR="#F4F4F4"> <B><FONT COLOR="#000080">Atendente:</FONT></B> </TD> <TD BGCOLOR="#F4F4F4"> <% rs=stm.executeQuery("SELECT nome_func FROM funcionarios WHERE id_func="+pid_func); //pesquisa while(rs.next()) {%> <FONT COLOR="#000000"><%=rs.getString("nome_func")%> <%}%> </FONT> </TD> <TD BGCOLOR="#F4F4F4"> <B><FONT COLOR="#000080">Mensageir</FONT></B> </TD> <TD BGCOLOR="#F4F4F4" COLSPAN=5> <% rs=stm.executeQuery("SELECT nome_func FROM funcionarios WHERE id_func="+pid_status); //pesquisa while(rs.next()) {%> <FONT COLOR="#000000"<%=rs.getString("nome_func")%> <%}%> </FONT> </TD> </TR> </TABLE><BR><%}if(i==0) out.print("Nenhum registro encontrado.");%><BR><BR><P ALIGN="left"> <A HREF='java script:history.back(1)'><IMG BORDER="0" SRC="imagens/voltar.jpg" WIDTH="75" HEIGHT="30"></A></p></BODY></HTML>Valeu galera!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Carinha.Se o teu tipo for igual a 1 ou 3, so vai trazer um registro mesmo, so vai dar mais de um registro se o tipo for igual a 2 e houver mais de um nome igual ao nome que for informado.falow.

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.