Based on the idea by "MadDog" at:
http://b2.iportalx.net/forum_posts.asp?TID=88&PID=797
- - - - - - - - - - - - - - -
To display the last xx posts on any page within the website outside the forum.
I tried other mods but some could not be placed on ANY page within the site and/or would show last 10 posts OK but if the last 10 were within the same topic then I got 10 lines all pointing to the same topic!
NOTE: code is for MS Access. See page above for other databases.
"last_ten_posts.asp" placed in the forum directory
<%
' to be used as an include on another page, like
' <!--#include virtual = "/forum/last_ten_posts.asp" -->
%>
<p style="text-align : left; font-size : 80%;color:#800000;">
Latest 10 Forum Posts
<br />
<%
Dim strLastestPostsModForumPath
Dim intLastestPostsTotal
Dim intCharacters
Dim strLastestPostsModCon
Dim adoCon
Dim rsAll
Dim strSQL
Dim intLoopCounter
Dim strTID
Dim strSubject
Dim strPID
'The absolute path to the forum
strLastestPostsModForumPath = "/forum/"
'How many new topics to show
intLastestPostsTotal = 10
'How many characters to show from the Topic title?
intCharacters = 18
'Database connection
'Default connection - adjust to suit
strLastestPostsModCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/forum/database/wwForum.mdb")
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open strLastestPostsModCon
Set rsAll = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT TOP " & intLastestPostsTotal & " "
strSQL = strSQL & " Topic_ID, Subject, Last_thread_ID "
strSQL = strSQL & " FROM tblTopic "
strSQL = strSQL & "ORDER BY Last_Thread_ID DESC;"
'open the connection
rsAll.Open strSQL, adoCon
'if there are records put into an array then close the connection
If NOT rsAll.EOF Then strArrayAll = rsAll.getRows()
rsAll.Close
Set rsAll = Nothing
adoCon.Close
Set adoCon = Nothing
'Loop through the array of forum posts
For intLoopCounter = 0 TO UBound(strArrayAll, 2)
'strArrayAll array lookup table
'0 = Topic_ID
'1 = Subject
'2 = Last_thread_ID
strTID = strArrayAll(0, intLoopCounter)
strSubject = strArrayAll(1, intLoopCounter)
strPID = strArrayAll(2, intLoopCounter)
'if someone uses a single quote in the title like: Where's
'the quote is stored as ' which is normally Ok unless the line gets truncated.
'I had a line truncated at 18 characters which left the & showing at the end of the line :-)
'so lets replace it with a single quote. May need to do the same for other "odd" characters. What about a double quote? etc.
strSubject = replace(strSubject, "'", "'")
'Crop the subject down to "intCharacters"
If Len(strSubject) > intCharacters then strSubject = Left(strSubject,intCharacters) & "..."
Response.Write "<a href=""" & strLastestPostsModForumPath & "forum_posts.asp?TID=" & strTID & "&" & "PID=" & strPID & "#" & strPID & """>" & strSubject & "</a><br />" & vbcrlf
Next
%>
</p>
Edited by wizmike - 30 July 2006 at 3:00am