Hvordan udskriver jeg de 5 seneste indlæg i alle fora?
Jeg har et forum hvor der er mange underfora!Har nedennævnte kode men der kan jeg kun definerer 1 forum ad gangen hvordan får jeg det lavet sådan at den udskriver følg.:
FORUM 1:
-Indlæg 1
-Indlæg 2
osv.
FORUM 2:
-Indlæg 1
-Indlæg 2
osv.
Koden:
<%
'*** Setup Options ***
'The forum number to get the messages from
intForum = 1
'How many messages to display
intMessages = 5
'The message will be truncated at the first space after this number of characters
intTruncate = 150
'The relative path to the database
strPath = "forum/admin/database/WWforum.mdb"
'The relative path to your main forum folder
strForumPath = "forum/"
'*** End Of Setup Options ***
'Connect to the database
strPath = Server.MapPath(strPath)
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strPath & ";"
Set cnnForum = Server.CreateObject("ADODB.Connection")
cnnForum.Open strConnection
'Get the time offset
strSQL = "SELECT Time_offset, Time_offset_hours FROM tblAuthor WHERE Author_ID = 1"
Set rstDateTime = cnnForum.Execute(strSQL)
If rstDateTime.Fields("Time_offset").Value = "+" Then
intOffset = rstDateTime.Fields("Time_offset_hours").Value
Else
intOffset = 0 - rstDateTime.Fields("Time_offset_hours").Value
End If
'Get the topic numbers to select from - i.e. the ones in whichever forum was chosen
strSQl = "SELECT Top " & intMessages & " Topic_ID FROM tblTopic WHERE Forum_ID = " & intForum
strSQL = strSQL & " ORDER BY Last_entry_date DESC"
Set rstTopics = cnnForum.Execute(strSQL)
'Get the last x messages from the forum
strSQL = "SELECT TOP " & intMessages & " Thread_ID, Topic_ID, Message, Message_date FROM "
strSQL = strSQL & "tblThread WHERE"
Do While Not rstTopics.EOF
strSQL = strSQL & " Topic_ID = " & rstTopics.Fields("Topic_ID").Value & " OR"
rstTopics.MoveNext
Loop
strSQL = strSQL & "DER BY Message_date DESC"
Set rstThreads = cnnForum.Execute(strSQL)
'Loop through the messsages
Do While Not rstThreads.EOF
'Get the message
strMessage = Truncate(StripCode(rstThreads.Fields("Message").Value))
'Get the message date
strDate = rstThreads.Fields("Message_date").Value
'Get the topic number
intTopic = rstThreads.Fields("Topic_ID").Value
'Get the thread number
intThread = rstThreads.Fields("Thread_ID").Value
'Move to the next record
rstThreads.MoveNext
'Calculate the time from the forum offset
strTime = FormatDateTime(DateAdd("h", intOffset, strDate), 4)
intLeft = Left(strTime, 2)
intRight = Right(strTime, 2)
strAMPM = ""
If intLeft > 24 Then
intLeft = intLeft - 24
strAMPM = ""
End If
If intLeft = 12 Then strAMPM = ""
If Left(intLeft, 1) = 0 Then intLeft = Right(intLeft, 1)
strTime = intLeft & "." & intRight & strAMPM
'Calculate the date from the forum offset
strDate = FormatDateTime(DateAdd("h", intOffset, strDate), 1)
'Work out the path to the topic this message came from
strTopicURL = strForumPath & "forum_posts.asp?TID=" & intTopic & "#" & intThread
'*** Customise The Results Here ***
%>
<b><% = strDate %> kl. <% = strTime %>:</b><br> <% = strMessage %> <font size="2"><br>
<a href="<% = strTopicURL %>" target="_blank">>>Læs mere</a></font>
<br>
<br>
<%
'*** End Customise Of The Results
Loop
'Clean up the mess we made :)
Set rstDateTime = Nothing
Set rstTopics = Nothing
Set rstThreads = Nothing
cnnForum.Close
Set cnnForum = Nothing
Set strConnection = Nothing
'And we are all done... the rest is the functions used in this script
Function StripCode(strInput)
'This function will remove any HTML in the given string
strStripped = strInput
intStart = InStr(1, strStripped, "<")
Do While intStart <> 0
intEnd = InStr(intStart, strStripped, ">")
strStripped = Left(strStripped, intStart - 1) & Mid(strStripped, intEnd + 1)
intStart = InStr(intStart + 1, strStripped, "<")
Loop
StripCode = strStripped
End Function
Function Truncate(strInput)
'This function will truncate the given string
'It will do so at the first space after the previously set number of characters
If Len(strInput) > intTruncate And intTruncate > 0 Then
intPosition = InStr(intTruncate, strInput, " ")
If intPosition <> 0 Then
strTruncated = Left(strInput, intPosition - 1) & "..."
Else
strTruncated = strInput
End If
Else
strTruncated = strInput
End If
Truncate = strTruncated
End Function
%>
Fomse:-)
