ricerca + paginazione

sara80

Nuovo Utente
21 Mag 2007
24
0
0
ho inserito una tabella con l interrogazione al db:

Codice:
<tr>
                <td><font size="+1">Ricerca</font></td>
              </tr>
			  <tr>
                <td height="1" BGCOLOR="#999999"><img src="images/puntino_trasparente.gif" width="100%" height="1"></td>
      		  </tr>
	          <%ricerca= Replace(request.form("ricerca"), "'", "''", 1, -1, 1)%> 
              <% if request.form("Prodotti")<>"" then%>
	          <tr>
                <td height="3"><img src="images/puntino_trasparente.gif" width="1" height="5"></td>
              </tr>
	          <%set libro=objConn.execute("select * from Prodotti where (Prodotto like '%"& ricerca &"%') or (PDescrizione like '%"& ricerca &"%')")%>
              <tr>
                <td><font size="1"><strong>Immobili:</strong></font></td>
              </tr>
			  <%if libro.eof=false then
			  do while not libro.eof%>
              <tr>
                <td><font size="1"><strong><img src="images/freccia2.gif" width="4" height="6"> <a href="scheda.asp?id=<%=libro.fields("id")%>"><%=libro.fields("Prodotto")%></a></strong></font></td>
              </tr>
			  <%libro.movenext
			  loop
			  else%>
              <tr>
                <td><font size="1"><strong>Nessun risultato trovato!</strong></font></td>
              </tr>
			  <%end if%>
	          <tr>
        	    <td height="3"><img src="images/puntino_trasparente.gif" width="1" height="5"></td>
      		  </tr>
	          <tr>
		        <td height="1" BGCOLOR="#999999"><img src="images/puntino_trasparente.gif" width="100%" height="1"></td>
      		  </tr>
			  <%libro.close
			  set libro=nothing%>

Pagina.asp completa:

Codice:
<% response.buffer=true %>
<% Server.ScriptTimeout = 300 %>
<!-- #include file="adovbs.inc"-->
<!-- #include file="connDb.asp"-->
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="200" valign="top"><table width="97%" border="0" cellspacing="0" cellpadding="0">
                <form name="form2" method="post" action="newsletter.asp?action=mail" onsubmit="return winopen1(this)" target="click1">              <tr>
                <td><font size="+1">Newsletter</font></td>
              </tr>
              <tr>
                <td><font size="1">iscriviti alla nostra newsletter per essere informato periodicamente sulle novità della casa editrice.</font></td>
              </tr>
              <tr>
                <td height="5"><img src="images/puntino_trasparente.gif" width="1" height="5"></td>
              </tr>
              <tr>
                <td>
				  <input name="newsletter" id="searchfield" type="text" class="medium" size="20" onFocus="if( this.value==this.defaultValue ) this.value='';" value="e-mail" /style="BACKGROUND-COLOR: #E3DE4F; BORDER-BOTTOM: #525961 1px double; BORDER-LEFT: #32373C 1px double; BORDER-RIGHT: #525961 1px double; BORDER-TOP: #32373C 1px double; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 11px; FONT-STYLE: normal; LINE-HEIGHT: normal">
                  <input type="submit" name="Submit" value="[VAI]" style="BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #537db9 0px; BORDER-LEFT: #537db9 0px; BORDER-RIGHT: #537db9 0px; BORDER-TOP: #537db9 0px; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 10px; FONT-STYLE: normal; LINE-HEIGHT: normal">
                </td>
              </tr>
			  </form>
              <tr>
                <td> </td>
              </tr>
              <form name="form1" method="post" onSubmit="return controllaRICERCA(this)" action="catalogo_ricerca.asp">
              <tr>
                <td><font size="+1">Ricerca nel sito</font></td>
              </tr>
              <tr>
                <td><font size="1">inserisci i termini per la ricerca</font></td>
              </tr>
              <tr>
                <td height="5"><img src="images/puntino_trasparente.gif" width="1" height="5"></td>
              </tr>
              <tr>
                <td><font size="1">cerca in:</font></td>
              </tr>
              <tr>
                <td><select name="Prodotti" >
<option value="Prodotti">Tutti i tipi</option>
<option value="Appartamento">Appartamenti</option>
<option value="Villa">Ville</option>
<option value="Rustico">Rustici</option>
</select>
                  <font size="1">Tipologia<br>
				  </font></td>
              </tr>
			  <tr>
                <td>
				  
                  <input type="submit" name="Submit2" value="[VAI]" style="BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #537db9 0px; BORDER-LEFT: #537db9 0px; BORDER-RIGHT: #537db9 0px; BORDER-TOP: #537db9 0px; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 10px; FONT-STYLE: normal; LINE-HEIGHT: normal">
                </td>
              </tr>
			  </form>
            </table>
<TABLE WIDTH="500" CELLPADDING="0" CELLSPACING="0" BORDER="0" align="center">
	<TR height="60" valign="justify">
		<TD align="justify">
			<font face="verdana" size="2" color="#333333">   </font>                                                                                               
		</TD>
	<TR>
		<TD>	
			<%
			iPageSize = 1 'NUMERO RECORD PER PAGINA

			If Request.QueryString("page") = "" Then
				iPageCurrent = 1
			Else
				iPageCurrent = CInt(Request.QueryString("page"))
			End If

			strSQL = "SELECT * FROM Prodotti ORDER BY ID ASC"
			Set objRS = Server.CreateObject("ADODB.Recordset")
			objRS.PageSize = iPageSize
			objRS.CacheSize = iPageSize
			objRS.Open strSQL, objConn, adOpenStatic, adLockReadOnly, adCmdText

			reccount = objRS.recordcount
			iPageCount = objRS.PageCount

			If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
			If iPageCurrent < 1 Then iPageCurrent = 1

			If iPageCount = 0 Then
				Response.Write "<p><b>Non sono stati trovati links.</b></p>"
			Else
				objRS.AbsolutePage = iPageCurrent
				iRecordsShown = 0
				%>
				
							<table width="480" align="center" border="1" cellspacing="1" cellpadding="3">
							<%
								'SI VISUALIZZA IL CONTENUTO DELLA STRINGA SQL
								'ALL'INTERNO DELLA TABELLA PRIMA DEFINITA
								cont=1
								Do While iRecordsShown < iPageSize And Not objRS.EOF
									Dim Rig, bg
									Rig = Rig + 1
									If Rig Mod 2 = 0 then
										bg = "#E4E4E4"
									Else
										bg = "#ccccff"	
									End if %>
									<tr>
                <td><font size="+1">Ricerca</font></td>
              </tr>
			  <tr>
                <td height="1" BGCOLOR="#999999"><img src="images/puntino_trasparente.gif" width="100%" height="1"></td>
      		  </tr>
	          <%ricerca= Replace(request.form("ricerca"), "'", "''", 1, -1, 1)%> 
              <% if request.form("Prodotti")<>"" then%>
	          <tr>
                <td height="3"><img src="images/puntino_trasparente.gif" width="1" height="5"></td>
              </tr>
	          <%set libro=objConn.execute("select * from Prodotti where (Prodotto like '%"& ricerca &"%') or (PDescrizione like '%"& ricerca &"%')")%>
              <tr>
                <td><font size="1"><strong>Immobili:</strong></font></td>
              </tr>
			  <%if libro.eof=false then
			  do while not libro.eof%>
              <tr>
                <td><font size="1"><strong><img src="images/freccia2.gif" width="4" height="6"> <a href="scheda.asp?id=<%=libro.fields("id")%>"><%=libro.fields("Prodotto")%></a></strong></font></td>
              </tr>
			  <%libro.movenext
			  loop
			  else%>
              <tr>
                <td><font size="1"><strong>Nessun risultato trovato!</strong></font></td>
              </tr>
			  <%end if%>
	          <tr>
        	    <td height="3"><img src="images/puntino_trasparente.gif" width="1" height="5"></td>
      		  </tr>
	          <tr>
		        <td height="1" BGCOLOR="#999999"><img src="images/puntino_trasparente.gif" width="100%" height="1"></td>
      		  </tr>
			  <%libro.close
			  set libro=nothing%>
			  <%end if%>
							  <%
								Cont = Cont + 1
									'POSIZIONAMENTO ALLA RIGA SUCCESSIVA DEL DB
									iRecordsShown = iRecordsShown + 1
									objRS.MoveNext
								Loop
								'PULIZIA DEGLI OGGETTI ADO
								objRS.Close
								Set objRS = Nothing
								%>
                            </table>
							<%End if%>
			<%If ipagecount <> 1 Then%>
		  <center><br>
				<table>
					<tr valign="middle">
						<td width="50%" align="center" valign="middle"><font face="verdana" size="1" color="#000000">
							<b><center>[
							<%if iPageCurrent-2 > 0 and iPageCurrent > 2 then%>
								 <a href="catalogo_ricerca.asp?page=1">Prima</a> 
							<%end if%>
							<%if iPageCurrent > 1 then%>
								 <a href="catalogo_ricerca.asp?page=<%=iPageCurrent-1%>">Precedente</a> 
							<%end if%>
							<%if iPageCount > 2 then
								if iPageCurrent-2 < 1 then da_pag = 1 else da_pag = iPageCurrent-2
								if iPageCurrent+2 > iPageCount then fino_a_pag = iPageCount else fino_a_pag = iPageCurrent+2
							else
								da_pag = 1
								fino_a_pag = iPageCount
							end if%>
							<%for i = da_pag to fino_a_pag%>
								<%if i = iPageCurrent then%>
									 <font color="red"><%=i%></font> 
								<%else%>	
									 <a href="catalogo_ricerca.asp?page=<%=i%>"><%=i%></a> 
								<%end if%>	
							<%next%>
							<%if iPageCurrent > 0 and iPageCurrent < iPageCount then%>
								 <a href="catalogo_ricerca.asp?page=<%=iPageCurrent+1%>">Successiva</a> 
							<%end if%>	
							<%if iPageCurrent+1 < iPageCount then%>
								 <a href="catalogo_ricerca.asp?page=<%=iPageCount%>">Ultima</a> 
							<%end if%>	
							]</center></b>
						</font></td>
					</tr>
					<tr>
						<td colspan="2" align="center"><font face="verdana" size="0.5" color="#333333">
							<center><br>
							Pagina 
								<font color="#FF0000"><b><%=iPageCurrent%></b></font>
								 di 
								<font color="#FF0000"><b><%=iPageCount%></b></font>
							</center>
						</font></td>
					</tr>
				</table>
		  </center>
			<%end if%>
			<%
			objConn.Close
			Set objConn = Nothing
			%>
		</TD>
	</TR>
</TABLE>

si connette al db tramite:

Codice:
<%set libro=objConn.execute("select * from Prodotti where (Prodotto like '%"& ricerca &"%') or (PDescrizione like '%"& ricerca &"%')")%>

cerca in tutti i record e campi, nella tabella Prodotti

Stampa a video tutti i Prodotti cercati:

Codice:
<%if libro.eof=false then
			  do while not libro.eof%>

http://www10.asphost4free.com/aspasp/catalogo.asp?scat=6

Se premete sul pulsante [Vai] sulla destra selezionando "Tutti i tipi" nella ricerca compare una tabella con i 4 record del db...
Vorrei che nei risultati della ricerca mi uscisse 1 record per ogni pagina e non 4..

e quando scorro con le pagine premendo su Successiva
mi uscissero gli altri 3 record che mancano..

ho fatto un po di confusione in questa parte di codice lo so.. :

Codice:
<%libro.movenext
			  loop
			  else%>
              <tr>
                <td><font size="1"><strong>Nessun risultato trovato!</strong></font></td>
              </tr>
			  <%end if%>
	          <tr>
        	    <td height="3"><img src="images/puntino_trasparente.gif" width="1" height="5"></td>
      		  </tr>
	          <tr>
		        <td height="1" BGCOLOR="#999999"><img src="images/puntino_trasparente.gif" width="100%" height="1"></td>
      		  </tr>
			  <%libro.close
			  set libro=nothing%>

con libro.movenext che si ripete anche con objRS.MoveNext, dovrei usarne solo uno di movenext.. chi mi dice dove inserirlo?.. ho fatto un po di prove ma non riesco a venirne a capo..
 
Ultima modifica:

sara80

Nuovo Utente
21 Mag 2007
24
0
0
penso perchè ci sono 4 risultati.. ma non sono sicura..domani provo ad aggiungere una riga nel db e ti faccio sapere.

grazie
 

sara80

Nuovo Utente
21 Mag 2007
24
0
0
ciao a tutti, ho risolto con la ricerca, c è solo un piccolo problema

form:

Codice:
<form name="form_ricerca" id="form_ricerca" method="post" action="catalogo_ricerca.asp">
<fieldset id="informazioni">
<label for="immobile">Tipologia:</label>
<select name="immobile" id="immobile" size="1" tabindex="6">
<option value="" selected>TUTTI</option>
<option value="appartamento">APPARTAMENTO</option>
<option value="villa singola">VILLA SINGOLA</option>
</select>
<br/>
<label for="località">Località:</label>
<select name="località" id="località" onChange="dennis(this[this.selectedIndex].value)" size="1" tabindex="10">
<option value="" selected>TUTTE</option>
<option value="trecastagni">TRECASTAGNI</option>
<option value="catania">CATANIA</option>

</select>
<br/>
<label for="prezzo">Prezzo:</label>
<select name="prezzo" id="prezzo" size="1" tabindex="11">
<option value="" selected>TUTTI</option>
<option value="200000,00">DA 200 A 400</option>
<option value="800000,00">FINO A 800</option>
</select>
<br/>
<input type="submit" name="Submit" value="Cerca" tabindex="18">
<br/>
</fieldset>
</form>


Codice:
<%
dim objConn
set objConn = server.createobject("ADODB.Connection")
objConn.open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = "&_
Server.MapPath("mdb-database\ecom.mdb")
sel_ses = request.form("immobile")
sel_reg = request.form("località")
sel_prov = request.form("prezzo")

Dim strRicerca
if sel_ses = "" and sel_reg = "*" and sel_prov = "*" then
strRicerca = " ORDER BY ID"
else
if sel_ses = "" and sel_reg <> "*" and sel_prov = "*" then
strRicerca = " WHERE località = '"& sel_reg &"' ORDER BY ID"
else
if sel_ses <> "" and sel_reg = "*" and sel_prov = "*" then
strRicerca = " WHERE immobile = '"& sel_ses &"' ORDER BY ID"
else
if sel_ses <> "" and sel_reg <> "*" and sel_prov = "*" then
strRicerca = " WHERE immobile = '"& sel_ses &"' AND località ='"& sel_reg &"' ORDER BY ID"
else
if sel_ses <> "" and sel_reg <> "*" and sel_prov <> "*" then
strRicerca = " WHERE immobile = '"& sel_ses &"' AND località ='"& sel_reg & "' AND prezzo ='"& sel_prov & "' ORDER BY ID"
end if
end if
end if
end if
end if

iPageSize = 2 'NUMERO RECORD PER PAGINA

If Request.QueryString("page") = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(Request.QueryString("page"))
End If


dim objRS, strSQL
set objRS = server.createobject("ADODB.Recordset")
strSQL = "SELECT * FROM tabella"
strSQL = strSQL & strRicerca
objRS.PageSize = iPageSize
objRS.CacheSize = iPageSize
objRS.open strSQL, objConn, adOpenStatic, adLockReadOnly, adCmdText

reccount = objRS.recordcount
iPageCount = objRS.PageCount
%>

il db è questo: http://www10.asphost4free.com/aspasp/db2.jpg

quando vado ad avviare la ricerca, selezionando

Tipologia: TUTTI
Località: TUTTE
Prezzo: TUTTI

funziona bene la ricerca!

Selezionando

Tipologia: APPARTAMENTO
Località: TUTTE
Prezzo: TUTTI

non mi da nessun risultato, non funziona la ricerca..

in poche parole se seleziono tutti i campi o li lascio tutti con TUTTI funziona..se seleziono un solo campo non funziona

ho sbagliato qualcosa qui:

Codice:
if sel_ses = "" and sel_reg = "*" and sel_prov = "*" then
strRicerca = " ORDER BY ID"
else
if sel_ses = "" and sel_reg <> "*" and sel_prov = "*" then
strRicerca = " WHERE località = '"& sel_reg &"' ORDER BY ID"
else
if sel_ses <> "" and sel_reg = "*" and sel_prov = "*" then
strRicerca = " WHERE immobile = '"& sel_ses &"' ORDER BY ID"
else
if sel_ses <> "" and sel_reg <> "*" and sel_prov = "*" then
strRicerca = " WHERE immobile = '"& sel_ses &"' AND località ='"& sel_reg &"' ORDER BY ID"
else
if sel_ses <> "" and sel_reg <> "*" and sel_prov <> "*" then
strRicerca = " WHERE immobile = '"& sel_ses &"' AND località ='"& sel_reg & "' AND prezzo ='"& sel_prov & "' ORDER BY ID"
end if
end if
end if
end if
end if

chi mi da una mano a sistemarlo per favore?

grazie
 
Ultima modifica:

sara80

Nuovo Utente
21 Mag 2007
24
0
0
Se inserisco dei valori in tutti e tre i campi non ci sono problemi.
I problemi escono fuori se vado a inserire dei valori in 2 soli campi (o 1 solo).
Vorrei che non inserendo niente in un campo mi prenda qualsiasi valore, invece no!!!!

c è nessuno? :( :( :(
 
Discussioni simili
Autore Titolo Forum Risposte Data
A [PHP] Problema paginazione motore di ricerca PHP 48
felino Pagina di ricerca: la paginazione non funziona WordPress 0
F access ricerca record con apostrofo. MS Access 0
C Ricerca Prodotti Woocommerce Javascript 0
U PHP creare un file excel dopo ricerca nel DB PHP 0
G Colorare menu select attraverso ricerca php PHP 0
L PHP motore di ricerca nel sito PHP 1
G Menù a tendina di ricerca con query PHP 1
R Problema query con ricerca id numerico PHP 2
L Mysql: Nascondere le pagine dopo una ricerca PHP 1
F Visualizzazione motore di ricerca SEO e Posizionamento 2
B Stringa sql per ricerca su più campi Database 1
F Funzione Glob - ricerca file contenente una parola PHP 1
P Ricerca campo data PHP 1
L titolo del sito nella pagina di ricerca di google SEO e Posizionamento 2
A Creare un modulo di ricerca avanzata con dreamweaver HTML e CSS 0
L Ricerca valore mysql e incremento PHP 73
E Problema motore di ricerca FULL_TEXT PHP 0
motleyrulez Ricerca filtro con Ajax PHP 1
Shyson [CSS] Posizionare casella di ricerca HTML e CSS 3
P Query di ricerca profonda MySQL 0
T Query per ricerca ritardo evento MS Access 7
B Campo ricerca domini HTML e CSS 4
V Ricerca volontari questionario tesi - Ricambio Offerte e Richieste di Lavoro e/o Collaborazione 0
L Ricerca sviluppatori PHP tempo indeterminato Milano Offerte e Richieste di Lavoro e/o Collaborazione 0
S [PHP] Creare collegamento filtri di ricerca al database PHP 6
L [PHP] Ricerca su search bar esterna PHP 1
D Ente di Formazione accreditato in Regione Lazio ricerca Front End Developer Offerte e Richieste di Lavoro e/o Collaborazione 3
N [WordPress] Ricerca tema WordPress 6
Alex_70 [PHP] Ricerca con risultati cliccabili PHP 21
Federico.Marcelo Alla ricerca di scrittori post guest Offerte e Richieste di Lavoro e/o Collaborazione 0
ANDREA20 [PHP] motore di ricerca nel sito PHP 11
O [PHP] Ricerca record tramite post PHP 7
GraceHawk [MS Access] Findfirst per ricerca record MS Access 1
T [PHP] Ricerca nel database PHP 2
A [Javascript] Mostrare un marker se è vicino al risultato di ricerca con google maps Javascript 3
V Semplice barra di ricerca con filtro categorie prodotti E-Commerce 0
A Ricerca con collegamento in altro sito web Discussioni Varie 0
C [PHP] Ricerca multipla, evitare if PHP 4
F [WordPress] Plugin Ricerca per e-commerce Woocommerce WordPress 1
M [OFFRO][RETRIBUITO] Milano IT Consulting SRL - Ricerca 1 Consulente PHP Offerte e Richieste di Lavoro e/o Collaborazione 0
D [ASP] Motore di ricerca interno su 2 tabelle Classic ASP 3
A [MySQL] Ricerca in PMA MySQL 0
andreas88 Da .htm a .php, perdo le mie posizioni su Google ricerca? SEO e Posizionamento 9
P Google risultati di ricerca inappropriati SEO e Posizionamento 1
Emix [PHP] Ricerca e modifica su due tabelle PHP 26
G [PHP] FORM DI RICERCA ESTESA PHP 2
borgo italia [PHP] ricerca caratteri accentati PHP 4
P [PHP] ricerca dati PHP 1
Emix [PHP][MYSQL] Ricerca avanzata tramite form PHP 6

Discussioni simili