Ir para conteúdo

POWERED BY:

Arquivado

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

nemtconto

Campos de FORM e Busca

Recommended Posts

Olá pessoas... aqui eu novamente...

 

Duas dúvidas meio que "bobas" mas como não uso tanto não lembro como fazer...

 

Primeira!

 

quando ele fizer uma busca, por exemplo a palavra "pneu" beleza, vai lá na tabela e tal, da um "like" e boa, ele vai procurar aonde tenha a palavra pneu e mostrar o resultado..

 

Mas não é isso que eu preciso, preciso que ele pegue APENAS a primeira palavra. por exemplo:

 

Pneu XYZ

Roda para Pneu

 

Se eu usar o "like" ele vai me trazer os dois resultados, porém eu quero APENAS a primeira palavra ou seja digitou PNEU me atrás apenas 1 registro e não os dois, claro que se tiver X produtos com o pneu sendo a primeira palavra tem que trazer todos menos os que tem pneu no meio ou no fim entenderam??? Mas isso vai variar por exemplo pneu é um exemplo do que ele buscou mas pode buscar Abobrinha que vai fazer o mesmo porém só aonde a primeira palavra é o que buscou!

 

 

A segunda dúvida é, tem uma caixa do form um "textfield" beleza... tem um "número" ali dentro, como poderia fazer por exemplo digita o número "4" e dar um enteder dai vai a função para UPDATE e talz ao invés de ter que clicar em um button para enviar... entenderam a dúvida?

 

Se alguém puder me dar um help ficarei agradecido!

 

Vlw´s!

Compartilhar este post


Link para o post
Compartilhar em outros sites

você pode fazer uma pesquisa pela palavra exata e tb especificar o k ira procurar ou kal termo irá utilizar, existem exemplos no forum, de uma pesquisada

 

tem uma caixa do form um "textfield" beleza... tem um "número" ali dentro, como poderia fazer por exemplo digita o número "4" e dar um enteder dai vai a função para UPDATE e talz ao invés de ter que clicar em um button para enviar... entenderam a dúvida?

 

naun entendi muito bem...

Compartilhar este post


Link para o post
Compartilhar em outros sites

1) "WHERE nome LIKE '" & palavra & "%'"

 

2) Não entendi essa dúvida. Para identificar o ENTER você tem que usar Javascript. Pesquise sobre isso.

Compartilhar este post


Link para o post
Compartilhar em outros sites

tem uma caixa do form um "textfield" beleza... tem um "número" ali dentro, como poderia fazer por exemplo digita o número "4" e dar um enteder dai vai a função para UPDATE e talz ao invés de ter que clicar em um button para enviar... entenderam a dúvida?

 

naun entendi muito bem...

 

é assim, imagina um textfield

 

_______________

|_____1________|

 

dentro dele o número 1 já vem por padrão pois ele incluiu um produto

 

agora se a pessoa quer comprar 3 ela apenas troca por 3

 

_______________

|_____3________|

 

E quando ela der o "enter" já faz o UPDATE na tabela mudando a quantidade de 1 para 3....

 

mas isso apenas dando o "enter" saca?

 

@HARGON então desse do WHERE é tranquilo, eu logo imaginei o "like" fiz e tá tudo certo...

 

só que não quero que ele busque no "meio" ou no "fim" daquele registro e sim a primeira palavra do registro entendeu?

Compartilhar este post


Link para o post
Compartilhar em outros sites

ao inves do ENTER use o evento onBlur, e execute a sql do Update,lembrando você pode fazer até por AJAX

Compartilhar este post


Link para o post
Compartilhar em outros sites

ao inves do ENTER use o evento onBlur, e execute a sql do Update,lembrando você pode fazer até por AJAX

 

Vou tentar...

 

Quanto ao Ajax não manjo não, até pensei nele... teria algum exemplo ou o que deveria pesquisar? thanks!

Compartilhar este post


Link para o post
Compartilhar em outros sites

da uma procurada k existem exemplos...

Compartilhar este post


Link para o post
Compartilhar em outros sites

<%

 

On Error Resume Next

 

 

 

PAGE_SIZE = 20

 

 

strURL = Request.ServerVariables("URL") ' URL ou Query string

 

 

 

'------------- q = input text

 

 

strSearch = Request.QueryString("q") ' the input text

 

If strSearch = "" Then

 

Server.htmlencode(Trim(Request.Form("q")))

 

End If

 

 

strSearch = Replace(strSearch, "'", "''")

 

 

'----------- p = RESULTADO PAGING

 

IF isnumeric(Request.QueryString("p")) = True OR Request.QueryString("p") = "" THEN

 

' Retrieve page to show or default to the first

If Request.QueryString("p") = "" OR Request.QueryString("p") < 1 Then

iPageCurrent = 1

Else

iPageCurrent = CInt(Request.QueryString("p"))

End If

 

ELSE

 

iPageCurrent = 1

 

 

END IF

 

p = iPageCurrent

 

 

 

IF isnumeric(Request.QueryString("t")) = True OR Request.QueryString("t") = "" THEN

 

' Retrieve t

 

If Request.QueryString("t") = "" OR Request.QueryString("t") < 1 Then

searchTable = 1 '1

Else

 

searchTable = 1 'CInt(Request.QueryString("t"))

 

End If

 

ELSE

 

searchTable = 2 '1

 

END IF

 

 

'------------------- m = METODo SEARCH

 

IF isnumeric(Request.QueryString("m")) = True OR Request.QueryString("m") = "" THEN

 

' Retrieve m

If Request.QueryString("m") = "" OR Request.QueryString("m") < 1 Then

strMethod = 2

Else

strMethod = CInt(Request.QueryString("m"))

End If

 

ELSE

 

strMethod = 2

 

 

END IF

 

 

 

'---------------FORM

%>

 

<form method="get" action="<%= strURL %>">

<p>

<input type="radio" name="m" value="1" <% IF strMethod = 1 THEN response.write "checked=""checked""" END IF%> />

E

<input type="radio" name="m" value="2" <% IF strMethod = 2 OR strMethod = "" THEN response.write "checked=""checked""" END IF%> />

OU

<input type="radio" name="m" value="3" <% IF strMethod = 3 THEN response.write "checked=""checked""" END IF%> />

Exato</p>

 

<p><input type="text" class="input3" name="q" value="<%= Trim(strSearch) %>" /></p>

 

<p><input type="submit" value="Procura" />

<br /><br /></p>

 

</form>

<%

 

 

 

If strSearch <> "" Then

 

 

Session("strSearch") = strSearch

 

IF isnumeric(Request.QueryString("t")) = True OR Request.QueryString("t") = "" THEN

 

' Retrieve t

 

If Request.QueryString("t") = "" OR Request.QueryString("t") < 1 Then

searchTable = 1 '1

Else

 

searchTable = 1 'CInt(Request.QueryString("t"))

 

End If

 

ELSE

 

searchTable = 1' 1

 

END IF

 

 

Select Case searchTable

 

Case CInt("1")

 

dbTable = "tMessages"

'strDBPath = Server.MapPath("/blogg/blog.mdb")

 

 

Case CInt("2")

 

'dbTable = "events"

'strDBPath = Server.MapPath("")

 

Case Else

 

dbTable = "tMessages"

'strDBPath = Server.MapPath("")

 

 

End Select

 

 

 

'------------------ SQL

 

 

 

'Separa strings em matrizes

'PARA AND ou cláusula SQL

 

 

 

IF searchTable = "1" THEN

IF strMethod < 3 THEN

 

 

If strMethod = 1 Then

strSplit = Replace(strSearch," "," and ")

Else

strSplit = Replace(strSearch," "," or ")

End If

 

 

colTerms = split(strSplit," and ",-1,1)

 

iUpperTerms = UBound(colTerms)

 

strWhereClause = ""

 

 

 

'FIELD CLAUSES

 

nr = 0

Do while nr <= 5

 

nr = nr + 1

 

searchField = CInt(nr)

 

Select Case searchField

 

Case CInt("1")

 

strTableInClause = "fDate"

 

Case CInt("2")

 

strTableInClause = "fHeadline"

 

Case CInt("3")

 

strTableInClause = "fMessage"

 

Case CInt("4")

 

strTableInClause = "fAuthor"

 

Case CInt("5")

 

strTableInClause = "fnota"

 

'Case Else

 

 

End Select

 

 

For iLoop = LBound(colTerms) to iUpperTerms

orTerms = split(colTerms(iLoop)," or ",-1,1)

iUpperOrTerms = UBound(orTerms)

strWhereClause = strWhereClause & ""

 

for iOrLoop = LBound(orTerms) to iUpperOrTerms

strWhereClause = strWhereClause & strTableInClause & " LIKE '%" & Trim(orTerms(iOrLoop)) & "%' "

 

if iOrLoop < iUpperOrTerms then

strWhereClause = strWhereClause & " OR "

end if

next

 

strWhereClause = strWhereClause & ""

 

if iLoop < iUpperTerms then

strWhereClause = strWhereClause & " AND "

end If

 

Next

 

if nr <= 4 then

strWhereClause = strWhereClause & " OR "

end if

 

Loop

 

 

ELSE

 

' MÉTODO 3 FrASE EXATa WHERE

 

strWhereClause = "fDate LIKE '%" & strSearch & "%' OR fHeadline LIKE '%" & strSearch & "%' OR fMessage LIKE '%" & strSearch & "%' OR fAuthor LIKE '%" & strSearch & "%' OR fnota LIKE '%" & strSearch & "%'"

 

END IF

 

 

strWhereClause2 = "WHERE (" & strWhereClause & ") AND (online = CBool(-1))"

 

' ORDER BY

strOrderClause = "ORDER BY fdate DESC"

 

 

 

IF strMethod = 3 THEN

 

strSQL = "SELECT * FROM "& dbTable &" "& strWhereClause2 &" "& strOrderClause &";"

 

ELSE

 

strSQL = "SELECT * FROM "& dbTable &" "& strWhereClause2 &" "& strOrderClause &";"

 

END IF

 

 

END IF

 

Response.write strSQL

 

'---------- END SQL

 

 

 

 

'--------- CONEXAO OPEN & EXE SQL

 

 

Set myRecSet = Server.CreateObject("ADODB.Recordset")

myRecSet.PageSize = PAGE_SIZE

myRecSet.CacheSize = PAGE_SIZE

 

' constantes

adOpenStatic = 3

adLockReadOnly = 1

adCmdText = &H0001

 

 

myRecSet.Open strSQL, sConn, adOpenStatic, adLockReadOnly, adCmdText

 

 

iRecordCount = myRecSet.RecordCount

iPageCount = myRecSet.PageCount

 

 

 

' RESULTADO COUNTER

 

strCountRecord = iRecordCount

 

If iPageCurrent = 1 Then

 

strCount = strCountRecord - iRecordCount + 1

 

Else

 

strCount = iPageCurrent * PAGE_SIZE - PAGE_SIZE + 1

 

'strCountRecord - + * iPageCurrent

 

End If

 

 

 

If iRecordCount = 0 Then

 

 

%> <p>Desculpa, sua busca não retornou resultados.<br />

Sua Busca por - <b><%=strSearch%></b> - não retornou documentos.</p>

 

<%

Else

 

myRecSet.AbsolutePage = iPageCurrent

 

If iRecordCount <= PAGE_SIZE then

toRecord = iRecordCount

else

toRecord = strCount + PAGE_SIZE - 1

End if

If toRecord => iRecordCount then

toRecord= iRecordCount

End if

 

%>

 

<p>Mostrando resultado <%=strCount%> - <%=toRecord%> de <%=iRecordCount %>. Paginas <%= iPageCurrent %> / <%= iPageCount %>. </p>

<br /><p>

<%

 

If iPageCurrent > 1 Then

%>

<a href="<%= strURL %>?m=<%= Server.URLEncode(strMethod) %>&t=<%= Server.URLEncode(searchTable) %>&q=<%= Server.URLEncode(strSearch) %>&p=<%= iPageCurrent - 1 %>" title="Previous">

‹‹</a>

<%

End If

 

 

For I = 1 To iPageCount

If I = iPageCurrent Then

 

%>

 

<%= I %>

<%

Else

%>

<a href="<%= strURL %>?m=<%= Server.URLEncode(strMethod) %>&t=<%= Server.URLEncode(searchTable) %>&q=<%= Server.URLEncode(strSearch) %>&p=<%= I %>" title="<%= I %>"><%= I %></a>

<%

End If

Next 'I

 

If iPageCurrent < iPageCount Then

%>

<a href="<%= strURL %>?m=<%= Server.URLEncode(strMethod) %>&t=<%= Server.URLEncode(searchTable) %>&q=<%= Server.URLEncode(strSearch) %>&p=<%= iPageCurrent + 1 %>" title="Next"> ››</a>

<%

End If

%></p>

 

<%

 

'----------------RESULTADO LOOP

 

 

Do While Not myRecSet.EOF And myRecSet.AbsolutePage = iPageCurrent

 

 

intNumMatches = 0

allregText = ""

regWriteOut = ""

 

If strSearch = " " then

strSearch = ""

End if

 

Set objRegExp = New RegExp

objRegExp.Global = True

objRegExp.IgnoreCase = True

 

 

If dbTable = "tMessages" then

allregText = myRecSet.Fields("fDate").Value & " " & myRecSet.Fields("fHeadline").Value & " " & myRecSet.Fields("fMessage").Value & " " & myRecSet.Fields("fAuthor").Value

End If

 

 

allregText = Replace(allregText, "<", "", 1, -1, 1)

allregText = Replace(allregText, ">", "", 1, -1, 1)

allregText = UTFtoISO(allregText)

 

If strMethod = 3 then

 

'Definir o padrão para pesquisar

objRegExp.Pattern = strSearch

 

'Pesquisar o arquivo para a frase

Set objMatches = objRegExp.Execute(allregText)

 

'Obter o número de vezes que a frase é acompanhada

intNumMatches = objMatches.Count

 

End if

 

If strMethod < 3 then

 

sarySearchWord = Split(strSearch, " ")

For intSearchLoopCounter = 0 to UBound(sarySearchWord)

 

'Definir o padrão para pesquisar

objRegExp.Pattern = "" & sarySearchWord(intSearchLoopCounter) & ""

 

'Pesquisar o arquivo para a frase

Set objMatches = objRegExp.Execute(allregText)

 

intNumMatches = intNumMatches + objMatches.Count

 

Next

End if

 

 

 

If intNumMatches => 1 Then

 

If intNumMatches > 1 then

regWriteOut = "" & intNumMatches & " hits."

Else

regWriteOut = "" & intNumMatches & " hit."

End If

 

End If

 

Set objRegExp = Nothing

 

 

 

%>

 

 

<% IF dbTable = "tMessages" THEN %>

<p><br /><br />

<%=strCount%>. <a href="default.asp?id=<%= myRecSet.Fields("id").Value %>" title="<%=myRecSet.Fields("fHeadline").Value%>"><%= myRecSet.Fields("fHeadline").Value %></a>

<br /><%= RemoveHTML(Left(myRecSet.Fields("fMessage").Value,instrrev(Left(myRecSet.Fields("fMessage").Value,280),"")))%>

<br />

Postado: <%= year(myRecSet.Fields("fdate").Value) & "-" & right("00" & cstr(month(myRecSet.Fields("fdate").Value)),2) & "-" & right("00" & cstr(day(myRecSet.Fields("fdate").Value)),2) & ". " & regWriteOut%>

</p>

<% END IF%>

 

 

<%

 

 

strCount = strCount + 1

myRecSet.MoveNext

Loop

 

 

'---------------- LOOP END

%>

<br /><br /><p>

<%

 

If iPageCurrent > 1 Then

%>

<a href="<%= strURL %>?m=<%= Server.URLEncode(strMethod) %>&t=<%= Server.URLEncode(searchTable) %>&q=<%= Server.URLEncode(Session("strSearch")) %>&p=<%= iPageCurrent - 1 %>" title="Previous">‹‹</a>

<%

End If

 

 

For I = 1 To iPageCount

If I = iPageCurrent Then

%>

 

<%= I %>

<%

Else

%>

<a href="<%= strURL %>?m=<%= Server.URLEncode(strMethod) %>&t=<%= Server.URLEncode(searchTable) %>&q=<%= Server.URLEncode(Session("strSearch")) %>&p=<%= I %>" title="<%= I %>"><%= I %></a>

<%

End If

Next 'I

 

If iPageCurrent < iPageCount Then

%>

<a href="<%= strURL %>?m=<%= Server.URLEncode(strMethod) %>&t=<%= Server.URLEncode(searchTable) %>&q=<%= Server.URLEncode(Session("strSearch")) %>&p=<%= iPageCurrent + 1 %>" title="Next">››</a>

<%

End If

%>

 

<%

 

End If

 

%></p>

<%

 

 

 

myRecSet.Close

Set myRecSet = Nothing

End If

 

%>

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.