La ricerca:
codice:
<html>
<head>
<title>Ricerca per parole chiave</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
#piedepagina{
position: relative;
left: 20px;
bottom: 25px;
}
-->
</style>
</head>
<body>
<%
call open_connection ()
parole=request("parole")
parole=lcase(parole) 'per (dopo) evidenziare indipendentemente dalle maiuscole
if len(parole) > 0 then
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT codice, prodotto, categoria, descrizione, tipologia, comune, provincia, info2 FROM prodotti WHERE"
ArrSearch = Split(parole)
x = 0
for each Word In ArrSearch
sql = sql & " (prodotto like '%" & word & "%' or descrizione like '%" & word & "%' or tipologia like '%" & word & "%' or info2 like '%" & word & "%')"
If Not x = UBound(ArrSearch) Then
sql = sql & " or"
End If
x = x + 1
Next
end if
'apro il rs
rs.Open sql, objConn, 3, 3 'cursore dinamico
if rs.eof then ' nessun record soddisfa la richiesta!
%>
<center><table border="0" width="80%">
<tr>
<td></td>
<td align="center">Nessuna inserzione soddisfa i criteri di ricerca</td>
<td>Altra ricerca</td>
</tr>
</table>
</center>
<%
else
'ZZZZZZZZZZZZZZZZZ ESTRAZIONE RECORDS SELEZIONATI ZZZZZZZZZZZZZZZZZZZZZZZ
do while not (rs.EOF)
codice_prodotto=rs.fields.item("codice").value
prod=rs.fields.item("prodotto").value
desc=rs.fields.item("descrizione").value
tipol=rs.fields.item("tipologia").value
com=rs.fields.item("comune").value
prov=rs.fields.item("provincia").value
inf=rs.fields.item("info2").value
codice_categoria=rs.Fields.Item("categoria").Value
SELECT CASE codice_categoria
CASE "RV"
nome_categoria = "Residenziale Vendita"
CASE "RL"
nome_categoria = "Residenziale Locazione"
CASE "CV"
nome_categoria = "Commerciale Vendita"
CASE "CL"
nome_categoria = "Commerciale Locazione"
END SELECT
' XXXXXXXX CONTEGGIO PAROLE CHIAVE xxxxxxxxxxxxxxxxxxxxxxxxxx
x = 0
conteggio=0
ArrSearch = Split(parole)
for each Word In ArrSearch
prova=prod&desc&tipol&prov&com&inf&nome_categoria
tet="0"
for y=1 to len(prova)
tet=instr(prova, word)
if tet<>0 then
conteggio=conteggio+1
prova=mid(prova,tet+1)
end if
next
x=x+1
next
' XXXXXXXXXXXXXX AGGIORNAMENTO CAMPO "NUMERO PAROLE CHIAVE" XXXXXXXXXXXXXXXXX
SQLcont= "UPDATE prodotti SET campo10='"&conteggio&"' where codice ='"&codice_prodotto&"'"
objConn.Execute SQLcont
rs.movenext
loop
'ZZZZZZZ PAGINAZIONE ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
numero=5 'notizie per pagina
controllo=numero
dim rs2, sql2
Set rs2 = Server.CreateObject("ADODB.Recordset")
pag = TRIM(Request.QueryString("pag")) 'paginazione
If pag="" Then
pag = 1
Else
pag = CInt(pag)
End If
' XXXXXXXXXXX NUOVA ESTRAZIONE RECORDS .............. XXXXXXXXXXXXXXXXXXXXXX
sql2 = "SELECT codice, prodotto, categoria, descrizione, tipologia, comune, provincia, info2 FROM prodotti WHERE"
ArrSearch = Split(parole)
x = 0
for each Word In ArrSearch
sql2 = sql2 & " (prodotto like '%" & word & "%' or descrizione like '%" & word & "%' or tipologia like '%" & word & "%' or info2 like '%" & word & "%')"
If Not x = UBound(ArrSearch) Then
sql2 = sql2 & " or"
End If
x = x + 1
Next
' XXXXXX .......... QUESTA VOLTA IN ORDINE DI NUMERO DI RICORRENZE DELLE PAROLE CHIAVE! XXXXXXXXXX
sql2=sql2 & " ORDER BY campo10 DESC"
'apro il rs
rs2.Open sql2, objConn, 3, 3 'cursore dinamico
tot = rs2.RecordCount 'conta i records nel recordset per la paginazione
%>
<table border="0" width="100%">
<tr>
<td></td>
<td align="center">La ricerca ha estratto <%=tot%> inserzioni rispondenti ai criteri inseriti</td>
<td>Altra ricerca</td>
</tr>
</table>
<table width='100%' border='1' cellpadding="2" cellspacing="0">
<%
rs2.move numero*(pag-1)
do while not (rs2.EOF or controllo=0)
codice_prodotto=rs2.fields.item("codice").value
prod=rs2.fields.item("prodotto").value
desc=rs2.fields.item("descrizione").value
tipol=rs2.fields.item("tipologia").value
com=rs2.fields.item("comune").value
prov=rs2.fields.item("provincia").value
inf=rs2.fields.item("info2").value
codice_categoria=rs2.Fields.Item("categoria").Value
SELECT CASE codice_categoria
CASE "RV"
nome_categoria = "Residenziale Vendita"
CASE "RL"
nome_categoria = "Residenziale Locazione"
CASE "CV"
nome_categoria = "Commerciale Vendita"
CASE "CL"
nome_categoria = "Commerciale Locazione"
END SELECT
'xxxxxxxxx EVIDENZIAZIONE PAROLE CHIAVE xxxxxxxxxxxxxxxxx
x=0
ArrSearch = Split(parole)
for each Word In ArrSearch
if prod <> "" then
prod=lcase(prod)
prod=Replace(prod, word, ""&word&"")
end if
x=x+1
next
x=0
ArrSearch = Split(parole)
for each Word In ArrSearch
if desc <> "" then
desc=lcase(desc)
desc=Replace(desc, word, ""&word&"")
end if
x=x+1
next
x=0
ArrSearch = Split(parole)
for each Word In ArrSearch
if tipol <> "" then
tipol=lcase(tipol)
tipol=Replace(tipol, word, ""&word&"")
end if
x=x+1
next
x=0
ArrSearch = Split(parole)
for each Word In ArrSearch
if com <> "" then
com=lcase(com)
com=Replace(com, word, ""&word&"")
end if
x=x+1
next
x=0
ArrSearch = Split(parole)
for each Word In ArrSearch
if prov <> "" then
prov=lcase(prov)
prov=Replace(prov, word, ""&word&"")
end if
x=x+1
next
x=0
ArrSearch = Split(parole)
for each Word In ArrSearch
if inf <> "" then
inf=lcase(inf)
inf=Replace(inf, word, ""&word&"")
end if
x=x+1
next
x=0
ArrSearch = Split(parole)
for each Word In ArrSearch
if nome_categoria <> "" then
nome_categoria=lcase(nome_categoria)
nome_categoria=Replace(nome_categoria, word, ""&word&"")
end if
x=x+1
next
'XXXXXXXXXXXXXX STAMPA A VIDEO XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
%>
<tr>
<td><%=prod %></td>
<td><%=desc %></td>
<!--<td><%=tipol %></td>
<td><%=com %></td>
<td><%=prov %></td>
<td><%=inf %></td> //-->
<td align="left" width="10%" > Visual scheda </td>
<% controllo = controllo - 1
rs2.Movenext
loop
%>
</tr></table>
<center><table border="0" width="250">
<tr>
<%
If ( pag > 1) Then
%>
<td widht="50" align="left">[img]barrow.gif[/img]</td>
<% else %>
<td widht="50"></td>
<%
end if
%>
<td width="220" align="center">
<%
if tot mod(numero)=0 then
lastpage=int(tot/numero)
else 'deve numerare l'ultima pagina anche se incompleta!
lastpage=int(tot/numero)+1
end if
for c=1 to lastpage
%>
<%=c%>
<%
next
%></td><%
If not rs2.eof Then
%>
</td><td widht="50" align="right">[img]arrow.gif[/img]</td>
<% else %> <td widht="50"></td>
<% end if %>
</tr>
</table>
</center>
<div id="piedepagina">Pag. <%=pag%> di <%=lastpage%></div>
<%
'rs.close
'rs=nothing
rs2.close
set rs2=nothing
end if
'chiudo tutto
call close_connection ()
%>
</body>
</html>
un po' più impegnativo, ma è discretamente commentato, non ti sarà difficile: connessione, nome database e relativi tabelle/campi, paginazione (le due immagini nella funzione di paginazione sono due freccette, puoi sostituirle...)