Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Paginazione con sopra ricerca

    Ciao a tutti. Grazie ai suggerimento di questo forum sono riuscito a paginare la pagina elenco.asp senza problemi che prende i dati da delle query esterne.

    Ecco il codice completo:

    <%@LANGUAGE="VBSCRIPT"%>
    <% option explicit %>
    <%
    '--> controllo se ha passato il login
    if Session("idUtente") = "" then
    Response.Redirect("Login.asp")
    end if
    '<-- controllo se ha passato il login
    %>

    <html>
    <head>
    <title>Elenco</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="../Stile.css" rel="stylesheet" type="text/css">

    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function popUpAvviso(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,men ubar=0,resizable=0,width=200,height=299,left = 315,top = 312');");
    }
    // End -->
    </script>

    </head>

    <body>

    <div align="center">
    <table border="0" width="780" id="table1" style="border-collapse: collapse; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px" bordercolor="#000000">
    <tr>
    <td width="184" style="border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px">
    <p style="margin-top: 0; margin-bottom: 0" align="center">
    [img]../images/logogif.gif[/img]</p>
    <p style="margin-top: 0; margin-bottom: 0" align="center">
    </p>
    </td>
    <td style="border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px">
    <p align="center" style="margin-top: 0; margin-bottom: 0">
    <font face="Verdana" size="4">Risultato della ricerca</font>
    </p>
    <p style="margin-top: 0; margin-bottom: 0"></td>
    </tr>
    </table>
    </div>





    <%
    dim rstElenco, strSQL, oConn
    strSQL = Session("Filtro")
    set rstElenco = server.createobject("ADODB.RECORDSET")
    rstElenco.open strSQL, oConnMdb1, 1, 3

    if not rstElenco.eof then

    '--> paginazione
    dim recordsPerPagina, page

    recordsPerPagina = 10

    page = Request.QueryString("page")

    if page = "" then
    page = 1
    end if

    rstElenco.pageSize = recordsPerPagina
    rstElenco.AbsolutePage = page

    '<-- paginazione
    %>
    </p>
    <fieldset style="width: 780" align="center">
    <legend title="">Elenco <%Response.Write(Session("DescrizioneFiltro"))%> - Pagina: <%=page%>di<%=rstElenco.PageCount%></legend>
    <table border="0" padding="2px" width="100%">
    <thead>

    <tr>
    <th>ID</th>
    <th>Compositore</th>
    <th>Titolo dell'opera</th>
    <th>Durata</th>
    <th width="1%">Formazione</th>
    <th>Anno pubblicazione</th>
    <th>Editore</th>
    <th>Numero
    di
    Catalogo</th>
    </tr>
    </thead>
    <tbody>
    <%
    dim i, ultimaPagina

    if (rstElenco.PageCount - rstElenco.Absolutepage) = 0 then
    ultimaPagina = true
    else
    ultimaPagina = false
    end if

    if ultimaPagina = true then
    do while not rstElenco.eof
    stampaRighe
    rstElenco.movenext
    loop
    else
    for i = 1 to recordsPerPagina
    stampaRighe
    if not rstElenco.eof then
    rstElenco.movenext
    end if
    next
    end if

    sub stampaRighe
    %>
    <tr bgcolor="#33CCFF">
    <td align="right" bgcolor="#66FF66"><%=rstElenco("IDOpera")%></td>
    <td bgcolor="#66FF66"><%=rstElenco("Compositore")%></td>
    <td bgcolor="#66FF66"><%=rstElenco("Titolo")%></td>
    <td bgcolor="#66FF66"><%=rstElenco("Durata")%></td>
    <td align="center" bgcolor="#66FF66"><%=rstElenco("Formazione")%></td>
    <td align="center" bgcolor="#66FF66"><%=rstElenco("Anno")%></td>
    <td align="center" bgcolor="#66FF66"><%=rstElenco("Edizione")%></td>
    <td align="center" bgcolor="#66FF66"><%=rstElenco("Numero")%></td>
    <td align="center" bgcolor="#66FF66"><%=rstElenco("codice_fiscale")%> </td>
    </tr>
    </tbody>
    <%
    end sub
    %>
    </table>
    <span class="barraMenu"><a class="nascondi" href="javascriptopUpAvviso('http://www.cassaedilenuorese.com/Legenda.htm')" title="Legenda pannello comandi">
    Legenda</a> <span class="nascondi">Pagina:</span><%

    '--> indietro
    if (page - 1) > 0 then
    %>
    <input class="nascondi" type="button" onClick="JavaScript: window.location.href='<%=Request.ServerVariables(" PATH_INFO")%>?page=1'" value="Prima">
    <input class="nascondi" type="button" onClick="JavaScript: window.location.href='<%=Request.ServerVariables(" PATH_INFO")%>?page=<%=page-1%>'" value="Precedente">
    <%
    end if
    '<-- indietro

    '--> avanti
    if (page + 1) <= rstElenco.PageCount then
    %>
    <input class="nascondi" type="button" onClick="JavaScript: window.location.href='<%=Request.ServerVariables(" PATH_INFO")%>?page=<%=page+1%>'" value="Successiva">
    <input class="nascondi" type="button" onClick="JavaScript: window.location.href='<%=Request.ServerVariables(" PATH_INFO")%>?page=<%=rstElenco.PageCount%>'" value="Ultima">
    <%
    end if
    '<-- avanti
    %></span>
    </fieldset>
    <%
    rstElenco.close
    set rstElenco = nothing
    else
    Response.Write "<center><h1>Dati non presenti.</h1>

    Home</p></center>"
    end if
    %>

    </body>
    </html>
    <%
    'set oConnMdb1 = nothing
    set oConn = nothing
    %>
    Funziona alla perfezione.
    Adesso vorrei però 'paginare' anche un risultato di ricerca sotto il form. Ci sto sbattendo la testa da ieri e non capisco dove stia sbagliando.

    Chi mi da una mano?

    Ecco il codice della RICERCA che non effettua paginazione ma che sputa fuori (dopo un'attesa che potete immaginare) migliaia di record in una sola pagina..

    <%@LANGUAGE="VBSCRIPT"%>
    <% option explicit %>
    <%
    '--> controllo se ha passato il login
    if Session("idUtente") = "" then
    Response.Redirect("Login.asp")
    end if
    '<-- controllo se ha passato il login
    %>

    <html>
    <head>
    <title>Ricerca</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="Stile.css" rel="stylesheet" type="text/css">

    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function popUpAvviso(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,men ubar=0,resizable=0,width=200,height=299,left = 315,top = 312');");
    }
    // End -->
    </script>

    </head>


    <div align="center">
    <table border="0" width="780" id="table1" style="border-collapse: collapse; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px" bordercolor="#000000">
    <tr>
    <td width="184" style="border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px">
    <p style="margin-top: 0; margin-bottom: 0" align="center">
    [img]images/logogif.gif[/img]</p>
    </td>
    <td style="border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px">
    <p align="center" style="margin-top: 0; margin-bottom: 0">
    <font face="Verdana" size="4">Cerca opere per titolo</font>
    </p>
    <p style="margin-top: 0; margin-bottom: 0"></td>
    </tr>
    </table>
    <p style="margin-top: 0; margin-bottom: 0"></div>

    <body background="../immagini/BackgroundMusic.gif">
    <div id="boxRicerca" class="nascondi">
    <font face="Tahoma" style="font-size: 9pt">
    <a name="top"></a>
    </font>
    <fieldset style="width: 780" align="center">
    <legend title=""><font face="Tahoma" style="font-size: 9pt">Ricerca opere per titolo</font></legend>
    <form action="<%=Request.ServerVariables("PATH_INFO") %>" method="POST" name="frmRicerca" id="frmRicerca" style="width: 780">


    <font face="Tahoma"><span style="font-size: 9pt">Digita il titolo o una parte di esso:<input type="text" name="titoloTXT" value="" size="78"></span></font></p>


    <font face="Tahoma"><span style="font-size: 9pt">
    <input name="Cerca" type="submit" value="Cerca" style="font-family: Verdana; font-size: 8pt"><input name="Cancella" type="reset" value="Cancella tutto" style="font-family: Verdana; font-size: 8pt"></span></font></p>
    </form>
    </fieldset><font face="Tahoma"><span style="font-size: 9pt"> </span></font>
    </div>
    <p style="margin-top: 0; margin-bottom: 0">
    <font face="Tahoma" style="font-size: 9pt">

    <%
    '--> viene visualizzata solo se è stata inviata la form
    if Request.ServerVariables("REQUEST_METHOD") = "POST" then
    dim rstElenco, strSQL, condizioneWhere

    strSQL = "SELECT * FROM Archivio"
    condizioneWhere = ""

    if Request.Form("titoloTXT") <> "" then
    condizioneWhere = " WHERE Titolo LIKE '%" & Request.Form("titoloTXT") & "%'"
    end if

    strSQL = strSQL & condizioneWhere & " ORDER BY Compositore ASC, Titolo ASC"
    set rstElenco = oConnMdb1.Execute(strSQL)

    if not rstElenco.eof then
    %>
    </font>
    </p>
    <fieldset style="width: 780" align="center">
    <legend title=""><font face="Tahoma" style="font-size: 9pt">Risultati ricerca</font></legend>
    <table border="0" padding="2px" width="780">
    <thead>
    <tr>
    <th align="center"><font face="Tahoma" style="font-size: 9pt">Codice</font></th>
    <th align="center"><font face="Tahoma" style="font-size: 9pt">Compositore</font></th>
    <th align="center"><font face="Tahoma" style="font-size: 9pt">Titolo</font></th>
    <th align="center"><font face="Tahoma" style="font-size: 9pt">Durata</font></th>
    <th align="center"><font face="Tahoma" style="font-size: 9pt">Formazione</font></th>
    <th align="center"><font face="Tahoma" style="font-size: 9pt">Anno di
    pubblicazione</font></th>
    <th align="center"><font face="Tahoma" style="font-size: 9pt">Editore</font></th>
    <th align="center"><font face="Tahoma" style="font-size: 9pt">Numero
    di
    catalogo</font></th>
    </tr>
    </thead>
    <tbody>
    <%
    dim tmp_prezzo
    do while not rstElenco.eof
    %>
    <tr bgcolor="#33CCFF">

    <td bgcolor="#66FF66"><font face="Tahoma" style="font-size: 9pt"><%=rstElenco("IDOpera")%></font></td>
    <td bgcolor="#66FF66"><font face="Tahoma" style="font-size: 9pt"><%=rstElenco("Compositore")%></font></td>
    <td bgcolor="#66FF66"><font face="Tahoma" style="font-size: 9pt"><%=rstElenco("Titolo")%></font></td>
    <td bgcolor="#66FF66"><font face="Tahoma" style="font-size: 9pt"><%=rstElenco("Durata")%></font></td>
    <td align="center" bgcolor="#66FF66">
    <font face="Tahoma" style="font-size: 9pt"><%=rstElenco("Formazione")%></font></td>
    <td align="center" bgcolor="#66FF66">
    <font face="Tahoma" style="font-size: 9pt"><%=rstElenco("Anno")%></font></td>
    <td align="center" bgcolor="#66FF66">
    <font face="Tahoma" style="font-size: 9pt"><%=rstElenco("Editore")%></font></td>
    <td align="center" bgcolor="#66FF66">
    <font face="Tahoma" style="font-size: 9pt"><%=rstElenco("Numero")%></font></td>

    </tr>
    </tbody>
    <%
    rstElenco.movenext
    loop
    %>
    </table>
    <font face="Tahoma" style="font-size: 9pt">
    <span class="barraMenu">Legenda
    </span>
    </font>
    </fieldset>
    <%
    rstElenco.close
    set rstElenco = nothing
    else
    Response.Write "<center><h1>Nessun'opera trovata nel database con il titolo o parte del titolo specificato.</h1>

    Home</p></center>"
    end if

    set rstElenco = nothing
    end if
    %>


    </font>
    </body>
    </html>
    <%
    set oConnMdb1 = nothing
    %>
    Grazie a tutti quelli che mi vorranno dare una zampa.

    Ciao.
    vuLCan

  2. #2
    Oddio

    Dunque un primo consiglio che ti do, è quello di non postare intere pagine html ma di postare solo parti "interessanti", in modo da evitare di ricercare il codice in mezzo a dettagli secondari (leggere il codice altrui, è una cosa quasi sempre faticosa :O)

    Tralasciando interamente la seconda parte, a te basta un piccolo form del tipo :
    codice:
    <form action="paginazione.asp">
    Titolo : <input type="text" name="srch_title">
    ....
    <input type="submit">
    </form>
    Nella paginazione devi :
    a) modificare la query opportunatamente, in modo da tener conto della ricerca dell'utente :
    codice:
    strSQL = SELECT * FROM nome_tabella WHERE "
    If Request.QueryString("srch_title") <> "" Then
    strSQL += "titolo LIKE '%" & Request.QueryString("srch_title") & "%' "
    End If
    ' idem per gli altri campi
    Nella pagina postata da te, ho visto che la query è inserita in una sessione ("filtro"), l'effetto è figo, ma imho è un uso improprio della session e porta dietro qualche svantaggio (ad es. se l'utente apre due finestre con la stessa pagina e due query diverse, il risultato potrebbe essere diverso da quello richiesto).
    b) modificare i bottoni della paginazione, in modo che si portino dietro l'informazione dei dati cercati :
    codice:
    ' un modo per evitare ripetizioni è quello di costruirsi la querystring all'inizio
    qs = ""
    If Request.QueryString("srch_title") <>  "" Then
    qs += "&srch_title=" & Request.QueryString("srch_title")
    End If
    ' idem per gli altri campi
    ...
    %>
    
    Per i bottoni :
    <input class="nascondi" type="button" onClick="java-script: window.location.href='<%=Request.ServerVariables("PATH_INFO")%>?page=1<%=qs%>'" value="Prima">
    Idem per gli altri bottoni
    ....
    Avevo scritto un esempio qlc annetto fa : http://www.dadamax.net/asp/esempi/es...?id_esempio=28
    Magari può esserti di aiuto (ma su internet ne trovi parecchi di esempi simili).

    Ciau!
    - Dean

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.