ricerca + paginazione

  • Creatore Discussione Creatore Discussione sara80
  • Data di inizio Data di inizio

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:
penso perchè ci sono 4 risultati.. ma non sono sicura..domani provo ad aggiungere una riga nel db e ti faccio sapere.

grazie
 
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:
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