% ' Sidan innehåller "Response.Redirect("???.asp")" ' ASP-sidan måste buffras innan den skickas från serven Response.Buffer = True If Session("AlreadyIn") <> "True" Then ' Automatisk förflyttning till följande webbsida. Response.Redirect("guestbook.asp") End If '================================================== ' Öppnar databasen ' Ladda include file som innehåller kommandon för att öppna databaskoplingen. '================================================== %>
<% '================================================================================
' Lista poster.
'================================================================================
If Request.QueryString("what") = "list" Then
' Declare our vars
Dim iPageSize ' How big our pages are
Dim iPageCount ' The number of pages we get back
Dim iPageCurrent ' The page we want to show
Dim strOrderBy ' A fake parameter used to illustrate passing them
Dim strSQL ' SQL command to execute
' Dim objPagingConn ' The ADODB connection object
Dim RecSet ' The ADODB recordset object
Dim iRecordsShown ' Loop controller for displaying just iPageSize records
Dim I ' Standard looping var
' Get parameters
iPageSize = 25 ' You could easily allow users to change this
' Retrieve page to show or default to 1
If Request.QueryString("page") = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(Request.QueryString("page"))
End If
' If you're doing this script with a search or something
' you'll need to pass the sql from page to page. I'm just
' paging through the entire table so I just hard coded it.
' What you show is irrelevant to the point of the sample.
'strSQL = "SELECT * FROM sample ORDER BY id;"
' Sept 30, 1999: Code Change
' Based on the non stop questions about how to pass parameters
' from page to page, I'm implementing it so I can stop answering
' the question of how to do it. I personally think this should
' be done based on the specific situation and is clearer if done
' in the same method on all pages, but it's really up to you.
' I'm going to be passing the ORDER BY parameter for illustration.
' This is where you read in parameters you'll need for your query.
' Read in order or default to id
If Request.QueryString("order") = "" Then
strOrderBy = "id"
ElseIf Request.QueryString("order") = "FromDateTime" Then
Response.Write "SQL Query: " & vbCrLf
strOrderBy = "FromDateTime"
Else
strOrderBy = Replace(Request.QueryString("order"), "'", "''")
End If
' Build our SQL String using the parameters we just got.
' strSQL = "SELECT * FROM sample ORDER BY " & strOrderBy & ";"
'strSQL = "SELECT * FROM guestbook_fun ORDER BY " & strOrderBy & DESC & ";"
strSQL = "SELECT * FROM guestbook_fun ORDER BY FromDateTime DESC"
' Some lines I used while writing to debug... uh "test", yeah that's it!
' Left them FYI.
'strSQL = "SELECT * FROM sample WHERE id=1234 ORDER BY id;"
'strSQL = "SELECT * FROM sample;"
'Response.Write "SQL Query: " & strSQL & "
" & vbCrLf
' Now we finally get to the DB work...
' Create and open our connection
' Set objPagingConn = Server.CreateObject("ADODB.Connection")
' objPagingConn.Open CONN_STRING, CONN_USER, CONN_PASS
' Create recordset and set the page size
' Set objPagingRS = Server.CreateObject("ADODB.Recordset")
' objPagingRS.PageSize = iPageSize
RecSet.PageSize = iPageSize
' You can change other settings as with any RS
'objPagingRS.CursorLocation = adUseClient
' objPagingRS.CacheSize = iPageSize
RecSet.CacheSize = iPageSize
' Open RS
' objPagingRS.Open strSQL, objPagingConn, adOpenStatic, adLockReadOnly, adCmdText
RecSet.Open strSQL, Connect, adOpenStatic, adLockReadOnly, adCmdText
' Get the count of the pages using the given page size
' iPageCount = objPagingRS.PageCount
iPageCount = RecSet.PageCount
' If the request page falls outside the acceptable range,
' give them the closest match (1 or max)
If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
If iPageCurrent < 1 Then iPageCurrent = 1
' Check page count to prevent bombing when zero results are returned!
If iPageCount = 0 Then
Response.Write "No records found!"
Else
' Move to the selected page
' objPagingRS.AbsolutePage = iPageCurrent
RecSet.AbsolutePage = iPageCurrent
' Start output with a page x of n line
%>
Antal meddelanden: <% =RecSet.RecordCount %>
Page <%= iPageCurrent %>
of <%= iPageCount %>
")
If iPageCurrent > 1 Then %>
[<< Prev]
<% End If
' Show page numbers:
For I = 1 To iPageCount
If I = iPageCurrent Then
Response.Write (I)
Else %>
<%= I %>
<% End If
Next 'I
If iPageCurrent < iPageCount Then %>
[Next >>]
<% End If
Response.Write vbCrLf
Response.Write("
")
' Loop through our records and ouput 1 row per record
iRecordsShown = 0
' Do While iRecordsShown < iPageSize And Not objPagingRS.EOF
Do While iRecordsShown < iPageSize And Not RecSet.EOF
%>
|
") If iPageCurrent > 1 Then %> [<< Prev] <% End If ' Show page numbers: For I = 1 To iPageCount If I = iPageCurrent Then Response.Write (I) Else %> <%= I %> <% End If Next 'I If iPageCurrent < iPageCount Then %> [Next >>] <% End If %> <% ' Slut på "list". End If %> <% '===================================================================================================================== ' modifiera post. '===================================================================================================================== If Request.QueryString("what") = "modify" Then %>
<B>[STOP]</B>
<% End If %> <% If Request.QueryString("what") = "modifyitynow" Then %> <% Uppdatera = "SELECT * FROM guestbook_fun WHERE ID = " & Trim(Request.QueryString("ID")) & " " RecSet.Open Uppdatera, Connect, adOpenStatic, adLockOptimistic RecSet("Name") = Request.Form("InName") RecSet("Email") = Request.Form("InEmail") RecSet("Homepage") = Request.Form("InHomepage") RecSet("Hometown") = Request.Form("InHometown") RecSet("About") = Request.Form("InAbout") RecSet("Comments") = Request.Form("InComments") RecSet("MyComments") = Request.Form("InMyComments") RecSet("OtherComments") = Request.Form("InOtherComments") If Request.Form("InNotShow") <> "" Then RecSet("NotShow") = "True" Else RecSet("NotShow") = "False" End If ' RecSet("ChangeFromIP") = Request.ServerVariables("REMOTE_ADDR") ' RecSet("ChangeFromDateTime") = Date + Time RecSet.Update RecSet.Close %>
Posten är nu uppdaterad !
<< Tillbaka till listan
<% End If %> <% '================================================================================ %> <% ' Radera person %> <% '================================================================================ %> <% If Request.QueryString("what") = "deleteitnow" Then %> <% Texter = "SELECT * FROM guestbook_fun WHERE ID = " & Request.QueryString("ID") & " " RecSet.Open Texter, Connect, adOpenStatic, adLockOptimistic RecSet.Delete RecSet.Close %>
Manual till Gästboken
STÄMMER EJ
Gästboken innehåller följande fält:
Fältnamn | Datatyp | |
ID | Räknare | |
FromIP | Text | |
FromDateTime | Datum/Tid | |
Name | Text | |
Text | ||
Homepage | Text | |
Hometown | Text | |
Text | PM | |
NotShown | Ja/Nej | Om posten skall visas utåt eller inte. |
TextComent | PM |
Sidan skall bli lösenordskyddad
lista alla poster, vilka som visas o inte
klicka på post för att få mer detaljer, även ändra
<% ' Slut på "manual". End If %>
[ Upp ]