Ir para conteúdo

POWERED BY:

Arquivado

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

REDS

Sistema de Busca em ASP!!

Recommended Posts

Boa tarde Pessoal;

 

 

 

Possuo um sistema de Busca, no qual esta funcionando perfeitamente. Somente não estou conseguindo inserir uma coisa. Gostaria de quando a busca fosse realizada no banco de dados e a mesma não tiver resultados, o sistema (resultado.asp) apareça algum aviso de que a busca não obteve resultados.

 

 

 

Segue abaixo os códigos para avaliação.

 

Espero que me ajudem neste pequeno detalhe!

 

Um grande abraço a todos!

 

 

 

CONEXÃO - conexao.asp

 

 

<%Dim MM_Conexao_STRINGMM_Conexao_STRING = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\site\conexao\banco.mdb"%>

FORMULÁRIO DE BUSCA - busca.asp

 

 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Untitled Document</title></head><body><form name"Pesquisa" method="get" action="Resultado.asp"><p>Digite aqui para Pesquisar </p><p><input type="text" name="palavra" value=""></p><p>  <input type="submit" name="Submit" value="Pequisar"></p></form></body></html>

RESULTADO DE BUSCA - resultado.asp

 

 

<%@LANGUAGE="VBSCRIPT"%><!--#include file="Connections/Conexao.asp" --><%Dim Busca__MMColParamBusca__MMColParam = "1"If (Request.QueryString("palavra") <> "") Then   Busca__MMColParam = Request.QueryString("palavra")End If%><%Dim BuscaDim Busca_numRowsSet Busca = Server.CreateObject("ADODB.Recordset")Busca.ActiveConnection = MM_Conexao_STRINGBusca.Source = "SELECT * FROM Biblioteca WHERE Titulo LIKE '%" + Replace(Busca__MMColParam, "'", "''") + "%'"Busca.CursorType = 0Busca.CursorLocation = 2Busca.LockType = 1Busca.Open()Busca_numRows = 0%><%Dim Repeat1__numRowsDim Repeat1__indexRepeat1__numRows = -1Repeat1__index = 0Busca_numRows = Busca_numRows + Repeat1__numRows%><%Dim MM_paramName %><%Dim MM_keepNoneDim MM_keepURLDim MM_keepFormDim MM_keepBothDim MM_removeListDim MM_itemDim MM_nextItemMM_removeList = "&index="If (MM_paramName <> "") Then  MM_removeList = MM_removeList & "&" & MM_paramName & "="End IfMM_keepURL=""MM_keepForm=""MM_keepBoth=""MM_keepNone=""For Each MM_item In Request.QueryString  MM_nextItem = "&" & MM_item & "="  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then	MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))  End IfNextFor Each MM_item In Request.Form  MM_nextItem = "&" & MM_item & "="  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then	MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))  End IfNextMM_keepBoth = MM_keepURL & MM_keepFormIf (MM_keepBoth <> "") Then   MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)End IfIf (MM_keepURL <> "")  Then  MM_keepURL  = Right(MM_keepURL, Len(MM_keepURL) - 1)End IfIf (MM_keepForm <> "") Then  MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)End IfFunction MM_joinChar(firstItem)  If (firstItem <> "") Then	MM_joinChar = "&"  Else	MM_joinChar = ""  End IfEnd Function%><% While ((Repeat1__numRows <> 0) AND (NOT Busca.EOF)) %>  <table width="550" border="0" cellspacing="0" cellpadding="0">	<tr>	  <td width="58">Título</td>	  <td width="492"><A HREF="detalhes.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "Código=" & Busca.Fields.Item("Código").Value %>"><%=(Busca.Fields.Item("Titulo").Value)%></A></td>	</tr>	<tr>	  <td>Autor</td>	  <td><A HREF="detalhes.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "Código=" & Busca.Fields.Item("Código").Value %>"><%=(Busca.Fields.Item("Autor").Value)%></A></td>	</tr>  </table>  <%   Repeat1__index=Repeat1__index+1  Repeat1__numRows=Repeat1__numRows-1  Busca.MoveNext()Wend%>  <p>	<%Busca.Close()Set Busca = Nothing%>

 

DETALHES DO RESULTADO - detalhes.asp

 

 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%><!--#include file="Connections/Conexao.asp" --><%Dim detalhes__MMColParamdetalhes__MMColParam = "1"If (Request.QueryString("Código") <> "") Then   detalhes__MMColParam = Request.QueryString("Código")End If%><%Dim detalhesDim detalhes_numRowsSet detalhes = Server.CreateObject("ADODB.Recordset")detalhes.ActiveConnection = MM_Conexao_STRINGdetalhes.Source = "SELECT * FROM Biblioteca WHERE Código = " + Replace(detalhes__MMColParam, "'", "''") + ""detalhes.CursorType = 0detalhes.CursorLocation = 2detalhes.LockType = 1detalhes.Open()detalhes_numRows = 0%><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Untitled Document</title></head><body><table width="550" border="0" cellspacing="0" cellpadding="0">  <tr>	<td width="110">Código</td>	<td width="440" height="30"><%=(detalhes.Fields.Item("Código").Value)%></td>  </tr>  <tr>	<td>Título</td>	<td height="30"><%=(detalhes.Fields.Item("Titulo").Value)%></td>  </tr>  <tr>	<td>Autor</td>	<td height="30"><%=(detalhes.Fields.Item("Autor").Value)%></td>  </tr></table></body></html><%detalhes.Close()Set detalhes = Nothing%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Verifique o código da tabela que esta fazendo a busca..se o código for vazio ou nulo estão não retornou resultado..

Compartilhar este post


Link para o post
Compartilhar em outros sites

faz assim:

 

<% if not Busca.eof then %> 'Detalhe
<% 
While ((Repeat1__numRows <> 0) AND (NOT Busca.EOF)) 
%>


  <table width="550" border="0" cellspacing="0" cellpadding="0">
	<tr>
	  <td width="58">Título</td>
	  <td width="492"><A HREF="detalhes.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "Código=" & Busca.Fields.Item("Código").Value %>"><%=(Busca.Fields.Item("Titulo").Value)%></A></td>
	</tr>
	<tr>
	  <td>Autor</td>
	  <td><A HREF="detalhes.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "Código=" & Busca.Fields.Item("Código").Value %>"><%=(Busca.Fields.Item("Autor").Value)%></A></td>
	</tr>
  </table>
  <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Busca.MoveNext()
Wend
%>
<% else %>
Nada encontrado
<% end if%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

faz assim:

<% if not Busca.eof then %> 'Detalhe<% While ((Repeat1__numRows <> 0) AND (NOT Busca.EOF)) %>  <table width="550" border="0" cellspacing="0" cellpadding="0">	<tr>	  <td width="58">Título</td>	  <td width="492"><A HREF="detalhes.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "Código=" & Busca.Fields.Item("Código").Value %>"><%=(Busca.Fields.Item("Titulo").Value)%></A></td>	</tr>	<tr>	  <td>Autor</td>	  <td><A HREF="detalhes.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "Código=" & Busca.Fields.Item("Código").Value %>"><%=(Busca.Fields.Item("Autor").Value)%></A></td>	</tr>  </table>  <%   Repeat1__index=Repeat1__index+1  Repeat1__numRows=Repeat1__numRows-1  Busca.MoveNext()Wend%><% else %>Nada encontrado<% end if%>
PERFEITO!!!!!!!!!!!!Muito Obrigado!!!!! http://forum.imasters.com.br/public/style_emoticons/default/clap.gif

Compartilhar este post


Link para o post
Compartilhar em outros sites

Qualquer coisa posta ai.

Sem querer ser chato!! Me tira uma duvida... eu posso realizar uma busca e obter os dados do banco de uma tabela? Tipo... tenho uma tabelha chamada "BIBLIOTECA" dentro dela, tenho 8 colunas, onde na minha atual, somente faz a busca na coluna "Titulo"... Eu posso fazer com que a conexão realize a busca em todas as 8 colunas?A conexão:
<%Dim BuscaDim Busca_numRowsSet Busca = Server.CreateObject("ADODB.Recordset")Busca.ActiveConnection = MM_Conexao_STRINGBusca.Source = "SELECT * FROM Biblioteca WHERE Titulo LIKE '%" + Replace(Busca__MMColParam, "'", "''") + "%'"Busca.CursorType = 0Busca.CursorLocation = 2Busca.LockType = 1Busca.Open()Busca_numRows = 0%>
Muito Obrigado jivandf!! http://forum.imasters.com.br/public/style_emoticons/default/joia.gif

Compartilhar este post


Link para o post
Compartilhar em outros sites

Sim exemplo:

 

" SELECT * FROM Biblioteca WHERE Titulo LIKE '%" + Replace(Busca__MMColParam, "'", "''") + "%' OR coluna02 LIKE '%" + Replace(Busca__MMColParam, "'", "''") + "%' OR coluna03 LIKE '%" + Replace(Busca__MMColParam, "'", "''") + "%' "

 

e assim vai.

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.