En der vil hjælpe mig med paging?
Jeg har følgende nyhedsside:'###################################################
'# Setup
'###################################################
' // Name of Template File.
NewsTemplatePath="nyheder.asp"
' // Virtuel Path. (Where the files are located)
NewsFilePath="NewsAndPoll/news/"
'// Database connection string
FinNewsConstr = "Provider=MICROSOFT.JET.OLEDB.4.0; Data Source="&server.mappath(NewsFilePath&"news.mdb")
' // Debug Mode. (Show Error Msg if any Errors)
NewsDebugMode=false
' // Date format. Set to 1033 if using American date format
Session.LCID = 3081
' ####################
' ## Look and feel ##
' ####################
' // newsBgImage : Used for background color,thin lines and graph bars.
newsBgImage = "215D84.gif"
' // newsFont : Used for text
newsFont = "<font face=""Verdana"" color=""#000000"" size=""2"">"
' // newsFont : Used for text in Box
newsFontBox = "<font face=""Verdana"" color=""#000000"" size=""1"">"
' // newsHeading : Heading for the Box.
' // Use a image to make it look nice, otherwise uncomment the other line and change the text and/or font
'newsHeading = "<img src="""&NewsFilePath&"images/news_text.gif"">"
newsHeading = "<b><font color=""#FFFFFF"" face=""Verdana"" size=""2"">Seneste nyt</font></b>"
'Number of max news items to show in box
newsMaxNo=3
'#####################################################################
'## Text used in script. Change this to your own words/Language ##
'#####################################################################
'Text for "more"
newsTxtMore="Læs mere"
'Text for "News Archive"
newsTxtNewsArchive="Nyhedsarkiv"
'###################################################
'# Start
'###################################################
' // Setup DBStuff
dim FinNewsDB,FinNewsRS
set FinNewsDB=server.createobject("ADODB.Connection")
set FinNewsRS=server.createobject("ADODB.Recordset")
' // Get mode we are in
dim sModeFin
sModeFin = LCase(request("FinNewsMode"))
SELECT CASE sModeFin
CASE "archive"
showArchive()
CASE "viewdetails"
showDetails()
CASE else
showNewsBox()
END SELECT
' // Cleanup
set FinNewsRS=nothing
set FinNewsDB=nothing
'############################################
'# showNewsBox()
'# Get the lastest "newsMaxNo" news items and show box
'############################################
function showNewsBox()
' // Get the data
FinNewsOpenDB()
FinNewsRS.open "select top "&newsMaxNo&" * from tblNews ORDER BY NewsDateTime DESC",FinNewsDB,1,1
if not (FinNewsRS.bof and FinNewsRS.eof) then
' // Write out table Header
%>
<table border="0" cellspacing="0" width="140">
<tr>
<td width="100%" bgcolor="#0000ff">
<table border="0" cellspacing="0" width="140" bgcolor="#ffffff">
<tr>
<td colspan="2" bgcolor="#0000ff" width="140" align="center"><img src="<%=NewsFilePath%>images/spacer.gif" height=3 width=3><br><%=newsHeading%><br><img src="<%=NewsFilePath%>images/spacer.gif" height=3 width=3></td>
</tr>
<tr>
<td width="140" valign="top" align="center" colspan="2"><img src="<%=NewsFilePath%>images/spacer.gif" height=4 width=1></td>
</tr>
<%
' // Write out each news item
while not FinNewsRS.eof
%>
<tr>
<td width="10" valign="top" align="right"><%=newsFontBox%>·</font></td>
<td width="130" valign="top" align="left"><%=newsFontBox%>(<%=myDateFormat(FinNewsRS("NewsDateTime"))%>)<br><%=FinNewsRS("Heading")%>. <a href="<%=NewsTemplatePath%>?FinNewsMode=ViewDetails&FinNewsID=<%=FinNewsRS("ID")%>"><br><%=newsTxtMore%></a></font><br><img src="<%=NewsFilePath%>images/spacer.gif" height=4 width=1></td>
</tr>
<%
FinNewsRS.movenext
wend
' // Write out table Footer
%>
<tr>
<td width="140" valign="top" align="center" colspan="2"><img src="<%=NewsFilePath%>images/<%=newsBgImage%>" height=1 width=95%></td>
</tr>
<tr>
<td width="140" valign="top" align="center" colspan="2"><%=newsFontBox%><a href="<%=NewsTemplatePath%>?FinNewsMode=Archive"><%=newsTxtNewsArchive%></a></font></td>
</tr>
</table>
</td>
</tr>
</table>
<%
FinNewsRS.close
FinNewsDB.close
end if
end function
'############################################
'# showArchive()
'# Show all the news in the Archive (Short form)
'############################################
function showArchive()
' // Get the data
FinNewsOpenDB()
FinNewsRS.open "select * from tblNews ORDER BY NewsDateTime DESC",FinNewsDB,1,1
if not (FinNewsRS.bof and FinNewsRS.eof) then
' // Write out table Header
%>
<table border="0" cellspacing="0" width="100%">
<tr><td width="140" valign="top" align="Left" colspan="2"><%=newsFont%><font size="2" color="#0000ff"><b><%=newsTxtNewsArchive%></b></font></font></td></tr>
<tr><td width="140" valign="top" align="center" colspan="2"><img src="<%=NewsFilePath%>images/spacer.gif" height=4 width=1></td></tr>
<%
' // Write out each news item
while not FinNewsRS.eof
%>
<tr>
<td width="10" valign="top" align="right"><%=newsFont%>·</font></td>
<td width="100%" valign="top" align="left"><%=newsFont%>(<%=myDateFormat(FinNewsRS("NewsDateTime"))%>)<br><%=FinNewsRS("Heading")%>. <a href="<%=NewsTemplatePath%>?FinNewsMode=ViewDetails&FinNewsID=<%=FinNewsRS("ID")%>"><br><%=newsTxtMore%></a></font><br><img src="<%=NewsFilePath%>images/spacer.gif" height=4 width=1></td>
</tr>
<%
FinNewsRS.movenext
wend
' // Write out table Footer
%>
</table>
<%
FinNewsRS.close
FinNewsDB.close
end if
end function
'############################################
'# showDetails()
'# Show the selected news item using the template
'############################################
function showDetails()
dim FinNewsID
FinNewsID=request("FinNewsID")
if FinNewsID="" then
Response.write("Error could not find ID")
end if
' // Get the data
FinNewsOpenDB()
FinNewsRS.open "select * from tblNews where ID="&FinNewsID,FinNewsDB,1,1
if not (FinNewsRS.bof and FinNewsRS.eof) then
' // Write out table Header
%>
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="10" valign="top" align="right"> </td>
<td width="100%" valign="top" align="left"><center><%=newsFont%><font size="2"><b><%=FinNewsRS("Heading")%></b></font><br>
<%=newsFont%>(<%=myDateFormat(FinNewsRS("NewsDateTime"))%>)</center><br>
<%=FinNewsRS("FullText")%></font><br><img src="<%=NewsFilePath%>images/spacer.gif" height=4 width=1></td>
<tr>
<td width="100%" valign="top" align="center" colspan="2"><%=newsFont%><a href="<%=NewsTemplatePath%>?FinNewsMode=Archive"><%=newsTxtNewsArchive%></a></font><br><br></td>
</tr>
</tr>
</table>
<%
FinNewsRS.close
FinNewsDB.close
end if
end function
'############################################
'# FinNewsOpenDB()
'# Open database, show error if any problems
'############################################
sub FinNewsOpenDB()
On ERROR Resume next
FinNewsDB.open FinNewsConstr, "",""
if Err.number<>0 then
Response.write("Nyheds Error : Kunne ikke åbne databasen, tjek om PollFilePath er sat rigtigt.")
Response.end
end if
ON ERROR GOTO 0
end sub
'#############################################
'# myDateFormat(myDate)
'# Make the date look nice. DD/MM/YYYY if euro
'#############################################
function myDateFormat(myDate)
myDate=FormatDateTime(myDate,2)
tmpArray = split( myDate, "/" )
if len(tmpArray(0))<2 then tmpArray(0)= "0"&tmpArray(0)
if len(tmpArray(1))<2 then tmpArray(1)= "0"&tmpArray(1)
if len(tmpArray(2))<4 then tmpArray(2)= "20"&tmpArray(2)
myDateFormat = join(tmpArray,"/")
end function
%>
Og vil gerne have paging på således at det kun vises 10 nyheder pr. side.
Har fundet dette men kan ikke finde ud af hvor/hvordan jeg skal bygge det ind:
<%
intPage = Request("page")
If isNumeric(intPage) = False Or intPage < 1 Then
intPage = 1
End If
Set rs = Server.CreateObject("ADODB.RecordSet")
strSQL = "SELECT LinkURL FROM Links"
strDSN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&Server.MapPath("/aspdigital/db/demo.mdb")
rs.Open strSQL, strDSN, 1
If Not (rs.BOF Or rs.EOF) Then
rs.PageSize = 10
rs.AbsolutePage = intPage
intRecCount = rs.PageSize
intPageCount = rs.PageCount
Response.Write "<p><b>Side " & intPage & " af " & intPageCount & "</b></p>"
Do While Not rs.EOF And intRecCount > 0
Response.Write rs("LinkURL") & "<br>"
intRecCount = intRecCount - 1
rs.MoveNext
Loop
End If
rs.Close
Set rs = Nothing
Response.Write "<p>Gå til side "
For intNum = 1 To intPageCount
Response.Write "<a href=paging.asp?page=" & intNum & ">" & intNum & "</a> "
Next
Response.Write "<p>"
If Clng(intPage) > 1 Then
Response.Write "<a href=paging.asp?page=" & intPage - 1 & "><<</a>"
Else
Response.Write "<<"
End If
Response.Write " "
If Clng(intPage) < Clng(intPageCount) Then
Response.Write "<a href=paging.asp?page=" & intPage + 1 & ">>></a> "
Else
Response.Write ">>"
End If
%>
