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

    creazione automatica di pagine

    devo realizzare una pagina che visualizzi tutti i record (in base alla query che metto) di un db.
    tali record sono circa duecento in tutto,quindi mi serve un codice che decida quanti record mettere in una pagina (ad esempio 10) e che metta quattro opzioni a fine pagina (inizio, successiva, precedente e ultima).
    il codice che ho preparato è questo:

    codice:
    sql = "Select * from Elenco_indirizzi where Categoria = 'Ristoranti' AND Recensione is null or Recensione = '' order by Nome "
             rs.Open sql, conn, 1, 3
             do while not rs.EOF 
             i = i + 1
             rs.movenext
             loop
    codice:
    if i = 0 then
             Response.Write("Nessun dato disponibile")
             end if
             rs.close
    codice:
    <td width="90" bgcolor="#FFEC00" align="center"><a href="list-rist-inc.asp?order=id">ID</td>
        <td width="90" bgcolor="#FFEC00" align="center"><a href="list-rist-inc.asp?order=nome">Nome</td>
        <td width="90" bgcolor="#FFEC00" align="center"><a href="list-rist-inc.asp?order=ind">Indirizzo</td>
        <td width="70" bgcolor="#FFEC00" align="center">Telefono</td>
        <td width="90" bgcolor="#FFEC00" align="center"><a href="list-rist-inc.asp?order=cit">Città</td>
        <td width="90" bgcolor="#FFEC00" align="center">Categoria</td>
        <td width="700" bgcolor="#FFEC00" align="center">Recensione</td>
        <td width="30" bgcolor="#FFEC00" align="center"><a href="list-rist-inc.asp?order=qual">Q</td>
        <td width="30" bgcolor="#FFEC00" align="center"><a href="list-rist-inc.asp?order=pre">P</td>
        <td width="30" bgcolor="#FFEC00" align="center"><a href="list-rist-inc.asp?order=serv">S</td>
        <td width="90" bgcolor="#FFEC00" align="center">Stelle</td>
        <td width="50" bgcolor="#FFEC00" align="center">Modifica</td>
      </tr>
      <%
      ord = Request.Querystring("order")
      if ord = "id" then
      ord = "ID" 
      end if
      if ord = "nome" then
      ord = "Nome" 
      end if
      if ord = "ind" then
      ord = "Indirizzo" 
      end if
      if ord = "cit" then
      ord = "Città"
      End IF
      if ord = "qual" then
      ord = "Qualita DESC"
      End IF
      if ord = "pre" then
      ord = "Prezzo DESC"
      End IF
      if ord = "serv" then
      ord = "Servizio DESC"
      End IF
    
      lettera = Request.Querystring("lettera")
      
      Dim Page_Size
      Dim Current_Page
      Dim Page_Count
    
      Page_Size = 20
    
      If Request("Page") = "" Then
      Current_Page = 1
      Else
      Current_Page = CInt(Request("Page"))
      End If
    
      Set rs=Server.CreateObject("ADODB.RecordSet")
      rs.CursorLocation = adUseClient
      rs.PageSize = Page_Size
                  
                  if lettera <> "" then
                  SQL="SELECT * From Elenco_indirizzi WHERE Categoria = 'Ristoranti' AND Recensione is null or Recensione = '' AND Titolo LIKE '" & lettera & "%'"
                  else
                  SQL="SELECT * From Elenco_indirizzi WHERE Categoria = 'Ristoranti' AND  Recensione is null or Recensione = '' ORDER BY "&ord&" "
                  end if
      
      rs.Open SQL, conn
      Page_Count = rs.PageCount
    
      If 1 > Current_Page Then Current_Page = 1
      If Current_Page > Page_Count Then Current_Page = Page_Count
    
      rs.AbsolutePage = Current_Page
    
      Do While rs.AbsolutePage = Current_Page And Not rs.EOF
    codice:
    do while not rs.EOF
           id=rs("ID")
           nome=rs("Nome")
           indirizzo=rs("Indirizzo")
           telefono=rs("Telefono1")
           citta=rs("Città")
           categoria=rs("Categoria")
           recensione=rs("Recensione")
           qualita=rs("Qualita")
           prezzo=rs("Prezzo")
           servizio=rs("Servizio")
           stelle=rs("Stelle")
           %>
           <tr>
           <td width="90" bgcolor="#FEEBCD" align="center">
           <%Response.Write(id)%>
           </td>
           <td width="90" bgcolor="#FEEBCD">
           <%Response.Write(nome)%>
           </td>
           <td width="90" bgcolor="#FEEBCD">
           <%Response.Write(indirizzo)%>
           </td>
           <td width="70" bgcolor="#FEEBCD" align="center">
           <%Response.Write(telefono)%>
           </td>
           <td width="90" bgcolor="#FEEBCD" align="center">
           <%Response.Write(citta)%>
           </td>
           <td width="90" bgcolor="#FEEBCD" align="center">
           <%Response.Write(categoria)%>
           </td>
           <td width="700" bgcolor="#FEEBCD" align="left">
           <%Response.Write(recensione)%>
           </td>
           <td width="30" bgcolor="#FEEBCD" align="center">
           <%Response.Write(qualita)%>
           </td>
           <td width="30" bgcolor="#FEEBCD" align="center">
           <%Response.Write(prezzo)%>
           </td>
           <td width="30" bgcolor="#FEEBCD" align="center">
           <%Response.Write(servizio)%>
           </td>
           <td width="90" bgcolor="#FEEBCD" align="center">
           <%Response.Write(stelle)%>
           </td>
           <td width="50" bgcolor="#FEEBCD">
           <p align="center"><a href="edit-rist-inc.asp?id=<%=rs("id")%>">
           [img]modifica.gif[/img]</td>
           </tr>
           <%
           rs.movenext
           loop
           %>
           <%
           loop
           %>
           <%
           rs.close
           set rs = nothing
      
      Response.Write "<center>"
      Response.Write "<td colspan=""10"" align=""center"">
    
    "
      If Current_Page = 1 Then
      Response.Write "<font color='#000000'>Inizio | "
      End If 
      If Current_Page >= 2 Then
      Response.Write "<< Inizio | " & vbCrLf
      End If 
      If Current_Page >= Page_Count Then
      Response.Write "<font color='#000000'>Successiva >|"
      End If 
      If Current_Page < Page_Count Then
      Response.Write "Successiva >" & "|" & vbCrLf
      End IF 
      If Current_Page <> 1 Then
      Response.Write "< Precedente  | " & vbCrLf
      Response.Write " " & vbCrLf
      End If 
      If Current_Page = 1 Then
      Response.Write "<font color='#000000'>< Precedente | "
      End If 
      If Current_Page <> Page_Count Then
      Response.Write "Ultima >>" & vbCrLf
      End If 
      If Current_Page >= Page_Count Then
      Response.Write "Ultima"
      End If 
      %>
    così, le quattro opzioni in fondo pagina mi vengono visualizzate (e se sono alla prima pagina "inizio" e "precedente" non sono linkabili), ma quando clicco su "successiva" mi rida esattamente la stessa pagina (con tutti i record) magari ordinati dalla lettera b in poi.
    se qualcuno fosse così gentile da aiutarmi gli sarei grato.

  2. #2
    Utente di HTML.it L'avatar di heroes3
    Registrato dal
    Aug 2001
    Messaggi
    2,483
    quello che stai cercando chiamasi paginazione
    se ne parlato molto nel forum fai una ricerca e sicuramente risolverai il tuo problema


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 © 2026 vBulletin Solutions, Inc. All rights reserved.