<% ' 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. '================================================== %> Ny sida 2 [ Start ] [ Lista ] [ Manual ] [ Guestbook ] [ Logga ut ]

 

<% '================================================================================ ' 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 %>


<% ' Spacing Response.Write vbCrLf ' Show "previous" and "next" page links which pass the page to view ' and any parameters needed to rebuild the query. Response.Write ("

") 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 %>
bgcolor="#99FF99" <% Else %> bgcolor="#FF9999" <% End If%>>
" target="_blank">ID: <% =RecSet("ID") %>, Datum: <% =RecSet("FromDateTime") %>, Namn: <% =RecSet("Name") %>, Från: <% =RecSet("Hometown") %>, E-post: <% =RecSet("Email") %>, Hemsida: <% =RecSet("Homepage") %>, Om: <% =RecSet("About") %>
<% ' Denna koden gör att radbrytningar fungerar ShowComments = RecSet("Comments") If ShowComments <> "" Then ShowComments = Replace(ShowComments , Chr(34), "''") ShowComments = Replace(ShowComments , vbCrLf, "
") %> <% =ShowComments %> <% Else %> # Kommentar saknas # <% End If %> <% ' Denna koden gör att radbrytningar fungerar ShowMyComments = RecSet("MyComments") If ShowMyComments <> "" Then ShowMyComments = Replace(ShowMyComments , Chr(34), "''") ShowMyComments = Replace(ShowMyComments , vbCrLf, "
") %>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<% =ShowMyComments %>
<% Else %>
# Egen kommentar saknas # <% End If %>
[ &page=<% =Request.QueryString("page") %>">Ta bort ]

<% ' Increment the number of records we've shown iRecordsShown = iRecordsShown + 1 ' Can't forget to move to the next record! ' objPagingRS.MoveNext RecSet.MoveNext Loop ' All done - close table End If ' Close DB objects and free variables 'objPagingRS.Close 'Set objPagingRS = Nothing 'objPagingConn.Close 'Set objPagingConn = Nothing ' Show "previous" and "next" page links which pass the page to view ' and any parameters needed to rebuild the query. Response.Write ("

") 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 %>

Redigera post

<% ' Visa endast en post. Visa = "SELECT * FROM guestbook_fun WHERE ID = " & Trim(Request.QueryString("ID")) & " " ' RecSet.Open Visa, Connect RecSet.Open Visa, Connect, adOpenStatic, adLockOptimistic %>
">
ID: <% =RecSet("ID") %>, Datum: <% =RecSet("FromDateTime") %>, IP<% =RecSet("FromIP") %>
Namn:
">
E-postadress:
">
Hemsida:
">
Hemort:
">
Om:
">
Meddelande

<B>[STOP]</B> 
Min kommentar
Andra kommentar
> Visa ej denna post.

<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 %> <% '================================================================================ ' Bekräfta radering av person '================================================================================ If Request.QueryString("what") = "delete" Then %> Vill du ta bort <% =Request.QueryString("ID") %> från listan ?

[ &page=<% =Request.QueryString("page") %>">Ja ] [ ">Nej - Tillbaka ]

 

<% 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 %>

Posten är nu borttagen från listan.
">Tillbaka
<% End If %> <% '================================================================================ ' Manual. '================================================================================ If Request.QueryString("what") = "manual" Then %>

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  
Email 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 ]