|
utilizzazione di un db
paginazione: ASP ricorsiva
<% PageNo = request("page")
If PageNo="" then
PageNo=1
End If %>
apertura del db
<%
set conn = server.createobject("adodb.connection")
conn.open "guestbook"
sqlstmt = "SELECT * from Guestbook ORDER BY Date DESC"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sqlstmt, conn, 3, 3
rs.Pagesize=10
rs.absolutepage=PageNo %>
' valori a disposizione
TotalRecs = rs.recordcount
TotalPages = cInt(rs.pagecount)
messaggi
If PageNo = 1 then
response.write "ci sono "
response.write TotalRecs & " righe in "
response.write TotalPages & " pagine"
End If
If rs.eof then
response.write "non ci sono righe."
response.end
End If
blocco di righe (con interessanti controlli)
x = 0
' visualizziamo 10 righe sulla pagina
For x = 1 to 10
If rs.eof then
Exit For
Else
When = rs("Date")
Name = rs("Name")
' togliamo le fastidiose doppie virgolette
Name = Replace(Name,"''","'")
City = rs("City")
State = rs("State")
Country = rs("Country")
Email = rs("Email")
URL = rs("URL")
' verifichiamo un campo vuoto
If IsEmpty(URL) or URL = "" then
Link = "no URL given"
Else
Link = "" & URL & ""
End If
Comments = rs("Comments")
Comments = replace(Comments, "''", "'")
Start = rs("Date")
%>
| <%= When %> |
| <%= Comments %> |
|
<% If IsEmpty(Email) or Email="" then
response.write(Name)
Else
response.write "" & Name & ""
End If
%> |
<%= City %> <%= State %> <%= Country %> |
<%= Link %> |
<%
rs.MoveNext
End If
Next
%>
mettiamo i bottoni di navigazione
(lingo, ma controlla anche prima e ultima)
response.write ""
response.write "| "
' we don't want "Previous" on the first page so we'll do this
If PageNo > 1 then
response.write ""
Else
response.write " "
End If
response.write " | "
' we don't want "Next" on the last page so we'll do this
If NOT rs.eof then
response.write ""
Else
response.write " "
End If
response.write " | "
e, finalmente, chiudiamo
conn.close
set conn = nothing
%>
|