Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1

    Come fare per impaginare??

    Io ho un database con un sacco di tabelle... come faccio ad inpaginare i dati contenuti in una sola tabella partendo dal presupposto che io uso questo metodo?

    <%

    'Seleziono le OPINIONI
    sql = "SELECT * FROM opinione where tipo='archivio' ORDER BY data, ora desc"
    set rsopia = conn.execute(sql)

    If (rsopia.BOF) and (rsopia.EOF) then
    %>

    <table cellspacing="2" cellpadding="2" width="100%" bgcolor="#333366">
    <TR>
    <TD>

    <FONT face="Arial, Helvetica, sans-serif" color="#ffffff" size="4">
    <hr color="#ffffff">
    NON CI SONO OPINIONI IN ARCHIVIO
    <hr color="#ffffff">
    </FONT>

    </TD>
    </TR>
    </table>

    <%
    else
    %>
    <%
    rsopia.Movefirst
    do until rsopia.EOF
    %>

    <table cellspacing="0" cellpadding="0" bgColor="#ffffff" width="100%">
    <TR>
    <TD>




    <FONT face="Arial, Helvetica, sans-serif" color="#333366" size="3">
    "><% = rsopia("titolo") %>
    </FONT>

    <hr color="#333366">
    </TR>
    </TD>

    </table>

    <%
    rsopia.Movenext
    loop
    %>
    <% end if %>
    <%
    rsopia.close
    set rsopia = nothing
    %>

    In poche parole vorrei visualizzare al massimo 5 record per pagina e poi avere la possibilità di andare avanti pagina per pagina...

  2. #2
    Ci sono vari metodi. Uno ottimo è usare una classe ad-hoc che funziona molto bene e che richiede solo pochissime facili modifiche per essere adattata al tuo script.

    Un attimo che la recupero.
    E' nato www.lombardiamotori.it

    www.universocase.it: il primo portale italiano di annunci immobiliari gratuiti e autogestiti!

  3. #3

    Meno male che qualcuno mi risponde...

    Ok aspetto ^_=

  4. #4
    Uhm.....l'età e l'arterio, non mi ricordavo che l'avevo pubblicata sul mio sito, la puoi vedere e prendere qui : c'è un file che spiega bene tutto e ci sono degli esempi di utilizzo.

    E' nato www.lombardiamotori.it

    www.universocase.it: il primo portale italiano di annunci immobiliari gratuiti e autogestiti!

  5. #5
    Qualcosa di più semplice e che si adatti al mio esmpio non c'è???

  6. #6
    Qualcosa di più semplice
    gulp! VVoVe:

    Temo che in alternativa troverai qualcosa di meno semplice, che per di più non potrai riutilizzare la prossima volta.

    E' chiaro che per lavorarci sopra dovresti conoscere almeno i fondamenti di ASP, ma dedicandoci un pochino di tempo questa classe dovrebbe fare al caso tuo....in alternativa posso postare il codice di un mio script che, oltre a presentare i records, provvede a impaginarli, ma, credimi, adattare quello sarebbe più complicato e anche meno corretto dal punto di vista informatico, dimmi tu........
    E' nato www.lombardiamotori.it

    www.universocase.it: il primo portale italiano di annunci immobiliari gratuiti e autogestiti!

  7. #7
    Si, ti prego, postami il tuo codice...

  8. #8
    Ooops, scusa ma ho postato il file sbagliato, un attimo...
    E' nato www.lombardiamotori.it

    www.universocase.it: il primo portale italiano di annunci immobiliari gratuiti e autogestiti!

  9. #9
    Ecco. Non spaventarti, è un motore di ricerca e perciò è complesso,
    ma tu recupera solo le istruzioni relative alla paginazione (poche righe
    verso l'inizio e poi la tabellina alla fine che crea i link pagina avanti... pagina indietro... e vai a pagina...), è la stessa che
    useresti in un file più semplice.

    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()
    
    checked1 = request("campo1")
    checked2 = request("campo2")
    checked3 = request("campo3")
    checked4 = request("campo4")
    checked5 = request("campo5")
    
    'esempio di ciclo al posto della serie di istruzioni sopra (nb: checked(i) diventa un array!):
    'dim checked(5)
    'for i=1 to 5 	
    	'checked(i) = request("campo"&i)	
    'next
    
    parole=trim(request("parole"))
    parole=lcase(parole) 
    
    if len(parole) > 0 then
    
    Set rs = Server.CreateObject("ADODB.Recordset")
    
    'xxxxxxxxxxxxxx estrazione records contenenti una o più parole chiave (indipendentemente da maiuscole/minuscole)xxxxxxxxxx
    'nb: 1) con = cerca solo le stringhe, con "like" cerca anche le sottostringhe 
    '	 2) diverso comportamento con "or" oppure "and"
    '	 3) vedi anche NB subito qui sotto!
    
    'NB: un'altra possibilità, anzichè splittare l'input, è:
    'sql = "SELECT * FROM  lorem2 WHERE campo1 LIKE '%"&parole&"%'  OR campo1 LIKE '%"&replace(parole," ","%")&"%'"
    '(questo esempio è solo per campo1)
    'sql = "SELECT * FROM lorem2 WHERE (("
    
    ArrSearch = Split(parole)
    x = 0
    for each word In ArrSearch
    word = trim(word)
    
      	If Len(checked1) <> 0 Then
         sql = sql & " campo1 like '%" & word & "%'"
        End If
    	  
      	If Len(checked2) <>  0 Then
         If Len(checked1) <> 0 Then sql = sql & " or"
         sql = sql & " campo2 like '%" & word & "%'"
        End If
    	
      	If Len(checked3) <> 0 Then
         If Len(checked1) <> 0 Or Len(checked2) <>  0 Then sql = sql & " or"
         sql = sql & " campo3 like '%" & word & "%'"
        End If
    		
    	If Len(checked4) <> 0 Then
         If Len(checked1) <> 0 Or Len(checked2) <>  0 Or Len(checked3) <>  0 Then sql = sql & " or"
         sql = sql & " campo4 like '%" & word & "%'"
        End If
    	
    	If Len(checked5) <> 0 Then
         If Len(checked1) <> 0 Or Len(checked2) <>  0 Or Len(checked3) <>  0 Or Len(checked4) <>  0 Then sql = sql & " or"
         sql = sql & " campo5 like '%" & word & "%'"
        End If
    	
    	sql = sql &")"
    	
    	If Not x = UBound(ArrSearch) Then sql = sql & " or ("
    x = x + 1
      
    Next
    sql = sql &")"
    
    'apro il rs
    rs.Open sql, objConn, 3, 3
    
    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>Nuova ricerca</td>
    	</tr>
    </table>
    </center>
    
    
    <%
    
    else
    
    ' XXXXXXXX CONTEGGIO PAROLE CHIAVE xxxxxxxxxxxxxxxxxxxxxxxxxx
    do while not (rs.EOF)
    
    			id=rs.fields.item("id").value
    			
    			if len(checked1) > 0 then
    				conto1 = lcase(rs.fields.item("campo1").value) 
    				'lcase perchè l'istruzione "instr" usata nel conteggio è case-sensitive!
    			end if
    			if len(checked2) > 0 then
    				conto2 = lcase(rs.fields.item("campo2").value)
    			end if
    			if len(checked3) > 0 then
    				conto3 = lcase(rs.fields.item("campo3").value)
    			end if
    			if len(checked4) > 0 then
    				conto4 = lcase(rs.fields.item("campo4").value)
    			end if
    			if len(checked5) > 0 then
    				conto5 = lcase(rs.fields.item("campo5").value)
    			end if
    						
    
    
    x = 0
    conteggio=0 
    
    ArrSearch = Split(parole)
    for each word In ArrSearch 
    word = trim(word)
    
    	prova=conto1&conto2&conto3&conto4&conto5
    	
    	tet=0
    		for y=1 to len(prova) 
    		tet=instr(prova, word) 'okkio: instr è case-sensitive!
    		
    			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 lorem2 SET campo6="&conteggio&" where id ="&id&""
    objConn.Execute SQLcont
    
    rs.movenext
    loop
    
    'chiudo rs
    rs.close
    set rs=nothing
    
    
    'ZZZZZZZ  PAGINAZIONE  ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
    
    numero=4 'records per pagina
    controllo=numero 'contatore dei records per pagina
    
    '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 * FROM lorem2 WHERE (("
    
    ArrSearch = Split(parole)
    x = 0
    for each word In ArrSearch
    word = trim(word)
    
      	If Len(checked1) <> 0 Then
         sql2 = sql2 & " campo1 like '%" & word & "%'"
        End If
    	  
      	If Len(checked2) <>  0 Then
         If Len(checked1) <> 0 Then sql2 = sql2 & " or"
         sql2 = sql2 & " campo2 like '%" & word & "%'"
        End If
    	
      	If Len(checked3) <> 0 Then
         If Len(checked1) <> 0 Or Len(checked2) <>  0 Then sql2 = sql2 & " or"
         sql2 = sql2 & " campo3 like '%" & word & "%'"
        End If
    		
    	If Len(checked4) <> 0 Then
         If Len(checked1) <> 0 Or Len(checked2) <>  0 Or Len(checked3) <>  0 Then sql2 = sql2 & " or"
         sql2 = sql2 & " campo4 like '%" & word & "%'"
        End If
    	
    	If Len(checked5) <> 0 Then
         If Len(checked1) <> 0 Or Len(checked2) <>  0 Or Len(checked3) <>  0 Or Len(checked4) <>  0 Then sql2 = sql2 & " or"
         sql2 = sql2 & " campo5 like '%" & word & "%'"
        End If
    	
    	sql2 = sql2 &")"
    	
    	If Not x = UBound(ArrSearch) Then sql2 = sql2 & " or ("
    x = x + 1
      
    Next
    
    sql2 = sql2 &")"
    
    ' XXXXXX .......... QUESTA VOLTA IN ORDINE DI NUMERO DI RICORRENZE DELLE PAROLE CHIAVE! XXXXXXXXXX
    
    sql2=sql2 & " ORDER BY campo6 DESC"
    
    'apro il rs
    
    rs2.open sql2, objConn, 3, 3 
    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>Nuova 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)
    			
    			id=rs2.fields.item("id").value
    			campo1=rs2.fields.item("campo1").value
    			campo2=rs2.fields.item("campo2").value
    			campo3=rs2.fields.item("campo3").value
    			campo4=rs2.fields.item("campo4").value
    			campo5=rs2.fields.item("campo5").value
    			
    					
    'xxxxxxxxx EVIDENZIAZIONE PAROLE CHIAVE xxxxxxxxxxxxxxxxx
    x=0
    'ArrSearch = Split(parole)
    for each word In ArrSearch
    word = trim(word)
    
    if len(checked1) > 0 then
    campo1=lcase(campo1) 
    'anche replace è case-sensitive: senza lcase non riconosce la sottostringa "word" (tutta minuscola)!
    campo1=Replace(campo1, word, ""&word&"")
    end if
    
    if len(checked2) > 0 then
    campo2=lcase(campo2) 
    campo2=Replace(campo2, word, ""&word&"")
    end if
    
    if len(checked3) > 0 then
    campo3=lcase(campo3) 
    campo3=Replace(campo3, word, ""&word&"")
    end if
    
    if len(checked4) > 0 then
    campo4=lcase(campo4) 
    campo4=Replace(campo4, word, ""&word&"")
    end if
    
    if len(checked5) > 0 then
    campo5=lcase(campo5) 
    campo5=Replace(campo5, word, ""&word&"")
    end if
    
    x=x+1
    next
    
    'XXXXXXXXXXXXXX STAMPA A VIDEO XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    			
    %>
    <tr>
    	<td><%=campo1%></td> 
    	<td><%=campo2%></td>
    	<td><%=campo3%></td>
    	<td><%=campo4%></td>
    	<td><%=campo5%></td> 
    	 
    	 
    <%			controllo = controllo - 1
    			rs2.Movenext
    
    	loop
    	
    	%>
    </tr></table>
    
    
    
    <center><table border="0" width="250">
    	<tr>
    <%
    If ( pag > 1) Then
    %>
    <td width="50" align="left">[img]barrow.gif[/img]</td>
    <% else %>
    <td width="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 width="50" align="right">[img]arrow.gif[/img]</td>
    <% else %> <td width="50"></td>
    <% end if %>
    </tr>
    </table>
    </center>
    
    
    
        
    <div id="piedepagina">Pag. <%=pag%> di <%=lastpage%></div>
    <%
    
    
    rs2.close
    set rs2=nothing
    
    end if
    end if
    'chiudo tutto
    call close_connection()
    
    %>
    
    </body>
    </html>
    E' nato www.lombardiamotori.it

    www.universocase.it: il primo portale italiano di annunci immobiliari gratuiti e autogestiti!

  10. #10
    Grazie di tutto ^_=

    Sei stata un'ottimo maestro ^_^

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.