Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Paginazione?

  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2006
    Messaggi
    7

    Paginazione?

    Ciao, voglio fare una pagina legata a un db, nella quale, una volta selezionato un record del db appaia la scheda dell'elemento corrispondente.
    Fin qui tutto ok.
    Il problema è che ad ogni record sono associate n immagini (non tante), e voglio che appaia una di queste immagini con sotto i controlli (testuali, tipo 1 2 3 4 ) per passare da una foto all'altra.
    ho trovato alcuni script online, ma non sono sicuro che facciano al mio caso...
    sapreste aiutarmi?

    Grazie
    michele

  2. #2
    Utente di HTML.it
    Registrato dal
    Nov 2006
    Messaggi
    7
    Ok, ho preso un esempio trovato qui sul forum, ho impostato la visualizzazione di 1 record per pagina, in realtà ne vedo 2, e cambiando pagina rimangono gli stessi (nb: le foto sono 2)
    che può essere?


    codice:
    <%
    function excess(argValue)
    	if not (int(argValue) = argValue) then argValue = int(argValue)+1	
    	excess = argValue
    end function
    
    
    function cleanLong(argValue)
    	on error resume next
    	if argValue = "" then : cleanLong = clng(0) : else : cleanLong = clng(trim(argValue)) : end if
    	if err.number <> 0 then cleanLong = 0
    	on error goto 0
    end function
    
    dim conn, rs, SQL, SQLwhere
    Set conn = Server.CreateObject("ADODB.Connection")
    set rs = Server.CreateObject("ADODB.Recordset")
    Conn.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & server.mappath("/laderchi2/db1.mdb") & " ; Persist Security Info = False"
    
    dim wbp_recordPerPage, wbp_totalRecords, wbp_totalPages, wbp_currentRecord, wbp_currentPage, wbp_lastcurrentRecord
    dim wbp_isEmpty
    dim wbp_baseQuerystring, wbp_basePage
    dim argPage
    
    '*** EDIT *** impostare quanti record in ogni pagina
    wbp_recordPerPage = 1
    
    argPage = cleanLong(request.QueryString("page"))
    if argPage < 1 then argPage = 1
    
    '* 1. selezionare SOLO gli id
    '* 2. applicare in questa query gli eventuali filtri di selezione
    SQL = "SELECT idfoto FROM tabellafoto where IDCane = 3  "
    rs.open SQL, Conn, 3, 3
    
    '* impostazione variabili di navigazione (pagine)
    wbp_totalRecords = cint(rs.recordcount)
    wbp_totalPages = excess(wbp_totalRecords / wbp_recordPerPage)
    wbp_currentRecord = ((argPage - 1) * wbp_recordPerPage) + 1
    if wbp_currentRecord > wbp_totalRecords then
    	wbp_currentPage = 1
    	wbp_currentRecord = ((wbp_currentPage - 1) * wbp_recordPerPage) + 1
    else
    	wbp_currentPage = argPage
    end if
    wbp_lastcurrentRecord = wbp_currentRecord + wbp_recordPerPage - 1
    if wbp_lastcurrentRecord > wbp_totalRecords then wbp_lastcurrentRecord = wbp_totalRecords
    
    SQLwhere = ""
    
    wbp_isEmpty = true
    
    if not rs.eof then
    	'* spostamento nel recordset
    	rs.pagesize = wbp_recordPerPage
    	rs.absolutepage = wbp_currentPage
    
    	wbp_isEmpty = false
    	
    	'* creazione seconda query (recordset completo, solo per gli ID selezionati nella prima query)
    	dim ii
    	for ii=0 to wbp_recordPerPage-1
    		'*** EDIT *** al posto di ID mettere il nome del campo ID della vostra tabella
    		SQLwhere = SQLwhere & " or id = " & rs("idfoto") & ""
    		rs.movenext
    		if rs.eof then exit for
    	next
    	set ii = nothing
    	rs.close
    	SQLwhere = right(SQLwhere,len(SQLwhere)-3)
    end if
    
    if not wbp_isEmpty then
    
    	'*** EDIT *** selezionare TUTTI i campi necessari
    	SQL = "SELECT * FROM tabellafoto WHERE IDCane = 3 "
    
    	set rs = conn.execute(SQL)
    	while not rs.eof
    		'*** EDIT *** STAMPA DEL RECORDSET (da personalizzare secondo le esigenze)
    		%><img src = "/laderchi2/<%=rs("linkfoto")%>"  /> <%
    		rs.movenext
    	wend
    	%>
    	<div class="page_navigator">
    	<span class="page_view"><%
    	
    		'*** EDIT *** pagina a cui puntare
    		wbp_basePage = "paginazione.asp"
    		'*** EDIT *** querystring aggiuntiva ( es: "&sort=date" )
    		wbp_baseQuerystring = ""
    		
    		%></span>
    <span class="topic-pages"><%
    		if wbp_totalPages > 1 then
    			%><span class="page_pagesnav"><%=wbp_totalPages%> pagine [ <%
    			if wbp_currentPage > 1 then
    				if wbp_currentPage > 2 then
    					%>&lt;&lt; <%
    				end if
    			%>&lt; <%
    				if wbp_currentPage - 3 > 0 then%><%=wbp_currentPage-3%> <% end if
    				if wbp_currentPage - 2 > 0 then%><%=wbp_currentPage-2%> <% end if
    				if wbp_currentPage - 1 > 0 then%><%=wbp_currentPage-1%> <% end if
    			end if
    			%><%=wbp_currentPage%> <%
    			if wbp_currentPage < wbp_totalPages then
    				if wbp_currentPage + 1 < wbp_totalPages + 1 then%><%=wbp_currentPage+1%> <% end if
    				if wbp_currentPage + 2 < wbp_totalPages + 1 then%><%=wbp_currentPage+2%> <% end if
    				if wbp_currentPage + 3 < wbp_totalPages + 1 then%><%=wbp_currentPage+3%> <% end if
    				%>&gt; <%
    				if wbp_currentPage < wbp_totalPages - 1 then
    					%>&gt;&gt; <% 
    				end if
    			end if
    		%> ]</span><%
    		else
    		%>1 pagina<%
    		end if%>
    	</span>
    	</div><%
    	
    else
    	'*** EDIT *** se il recordset è vuoto...
    	response.write "nessun record"
    	
    end if
    
    
    %>

  3. #3
    Utente di HTML.it
    Registrato dal
    Nov 2006
    Messaggi
    7
    ho risolto, con un codice trovato in rete, la paginazione.
    rimane però il problema che vorrei il cambio di foto all'interno della pagina, senza cambiare il resto.
    Ora ho incluso la paginazione come procedura all'interno della pagina principale, come possono essere le variazioni?

    Grazie
    michele

    codice:
    <%
    
    Sub paginazione()
    Dim strCon, oCon, pages, Rec, DisplayNum, i, page, SQL, ipage, z
    
    Const adOpenForwardOnly = 0
    Const adLockReadOnly = 1
    Const adUseClient = 3
    Const adCmdText = 1 
    
    page = request.querystring("page")
    If page = "" Then
    page = 1
    else
    page = cint(page)
    End If
    
    DisplayNum = 0
    
    Set oCon = Server.CreateObject ("ADODB.Connection")
    Set Rec = Server.CreateObject ("ADODB.Recordset")
    
    oCon.Open ("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = "& Server.MapPath("/laderchi2/db1.mdb"))
    Rec.PageSize = 1
    Rec.CursorLocation = adUseClient 
    SQL = "SELECT * FROM tabellafoto where idcane =3 " 
    Rec.Open SQL, oCon
    
    if Rec.EOF OR Rec.BOF Then
    response.write "
    
    "
    
    response.write "<p align=center>Sorry, There is no result ... </p>"
    else
    
    ipage = Rec.PageCount 
    
    if page = 0 or page > ipage Then
    Rec.AbsolutePage = ipage
    else
    Rec.AbsolutePage = page
    end if
    
    Do While Not Rec.EOF AND DisplayNum < 1
    
    %><center><img src = "/laderchi2/<%=rec("linkfoto")%>"  /> </center><%
    
    DisplayNum = DisplayNum + 1
    Rec.MoveNext
    Loop
    
    end if
    
    If ipage > 1 Then
    response.write "<p align=center>"
    
    For z = 1 to ipage
    If z = page then
    pages = pages & page & " "
    Else 
    pages = pages & " <a href=?page=" & z & ">" & z & "</a>" & " "
    End If 
    Next 
    response.write pages & ""
    End If
    
    response.write "[/b]</p>"
    Rec.Close
    oCon.Close
    set Rec = nothing
    set oCon = nothing
    
    end sub
    %>

  4. #4
    Utente di HTML.it
    Registrato dal
    Nov 2006
    Messaggi
    7
    niente, eh?

    Michele

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