Ho scritto ste due righe di getto, senza controllare... provali e poi vediamo cosa non va... devi configurare la stringa di connessione (vedi codice in neretto).
Sono due pagine:
form.html
codice:
<form name="ricerca" method="get" action="ricerca.asp">
Titolo <input type="text" name="titolo" /> *
Genere <input type="text" name="genere" />
Regista <input type="text" name="regista" />
Anno <input type="text" name="anno" size="4" />
<input type="submit" value="CERCA" />
</form>
* campo obbligatorio
ricerca.asp
codice:
<%
function fixQuotes(theString)
if inStr(theString,"'") > 0 then theString = replace(theString,"'","''")
fixQuotes = theString
end function
function buildSQL(theField,theValue,theOperator)
tmpSQL = ""
if inStr(theValue," ") > 0 then
theValue = split(theValue)
for i = 0 to uBound(theValue)
tmpSQL = tmpSQL & theField & " LIKE '%" & theValue(i) & "%' "
if i < uBound(TheValue) then tmpSQL = tmpSQL & theOperator & " "
next
else
tmpSQL = theField & " LIKE '%" & TheValue & "%' "
end if
buildSQL = tmpSQL
end function
eseguiRicerca = false
risultatiPerPagina = 10
titolo = trim(request.queryString("titolo"))
genere = trim(request.queryString("genere"))
regista = trim(request.queryString("regista"))
anno = trim(request.queryString("anno"))
pagina = request.queryString("pagina")
if len(pagina) = 0 or (not isNumeric(pagina)) then
pagina = 1
else
pagina = cLng(pagina)
end if
scriptPage = request.serverVariables("PATH_INFO")
sql = "SELECT * FROM tabellaFilm WHERE "
if len(titolo) > 0 then
eseguiRicerca = true
sql = sql & "(" & buildSQL("titolo",fixQuotes(titolo),"OR") & ") "
end if
if len(genere) > 0 then
sql = sql & "AND (" & buildSQL("genere",fixQuotes(genere),"OR") & ") "
end if
if len(regista) > 0 then
sql = sql & "AND (" & buildSQL("regista",fixQuotes(regista),"OR") & ") "
end if
if len(anno) = 4 and isNumeric(anno) then
sql = sql & "AND (anno = " & anno & ")"
end if
if eseguiRicerca then
set conn = server.createObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.mapPath("\db\db.mdb")
set rs = server.createObject("ADODB.Recordset")
rs.open sql, conn, 3, 1
if not rs.eof then
rs.pageSize = risultatiPerPagina
rs.absolutePage = pagina
response.write "Risultato della ricerca.
"
response.write "Titolo: " & titolo & "
"
response.write "Genere: " & genere & "
"
response.write "Regista: " & regista & "
"
Response.write "Anno: " & anno & "
"
response.write "Risultati disponibili: " & rs.recordCount & "
"
response.write "Sei a pagina " & pagina & " di " & rs.pageCount & "
"
for r = 1 to risultatiPerPagina
if not rs.eof then
response.write "
" & rs("titolo") & "
"
response.write rs("genere") & "
"
response.write rs("regista") & "
"
response.write rs("anno") & "</p>"
rs.moveNext
else
exit for
end if
next
for p = 1 to rs.pageCount
if p = pagina then
response.write " " & p & " -"
else
response.write " " & p & " -"
end if
next
else
response.write "Nessun risultato disponibile"
end if
rs.close
set rs = nothing
conn.close
set conn = nothing
else
response.write "E' necessario specificare almeno il titolo del film"
end if
%>