'Get the last x posts from the database
strSQL = "" & _
"SELECT "
If strDatabaseType = "SQLServer" OR strDatabaseType = "Access" Then
strSQL = strSQL & " TOP " & intLatestPostsMaxNo & " "
End If
strSQL = strSQL & _
"" & strDbTable & "Forum.Forum_ID, " & strDbTable & "Forum.Forum_name, " & strDbTable & "Topic.Topic_ID, " & strDbTable & "Topic.Subject, " & strDbTable & "Thread.Thread_ID, " & strDbTable & "Thread.Message_date, " & strDbTable & "Author.Author_ID, " & strDbTable & "Author.Username, " & strDbTable & "Thread.Message " & _
"FROM " & strDbTable & "Forum, " & strDbTable & "Topic, " & strDbTable & "Author, " & strDbTable & "Thread " & _
"WHERE " & strDbTable & "Forum.Forum_ID = " & strDbTable & "Topic.Forum_ID " & _
"AND " & strDbTable & "Topic.Last_Thread_ID = " & strDbTable & "Thread.Thread_ID " & _
"AND " & strDbTable & "Author.Author_ID = " & strDbTable & "Thread.Author_ID "
'Check permissions
strSQL = strSQL & _
"AND (" & strDbTable & "Topic.Forum_ID " & _
"IN (" & _
"SELECT " & strDbTable & "Permissions.Forum_ID " & _
"FROM " & strDbTable & "Permissions" & strDBNoLock & " " & _
"WHERE (" & strDbTable & "Permissions.Group_ID = " & intGroupID & " OR " & strDbTable & "Permissions.Author_ID = " & lngLoggedInUserID & ") " & _
"AND " & strDbTable & "Permissions.View_Forum = " & strDBTrue & _
")" & _
")"
'Don't include password protected forums
strSQL = strSQL & "AND (" & strDbTable & "Forum.Password = '' OR " & strDbTable & "Forum.Password Is Null) "
strSQL = strSQL & "AND (" & strDbTable & "Topic.Hide = " & strDBFalse & " AND " & strDbTable & "Thread.Hide = " & strDBFalse & ") " & _
"ORDER BY " & strDbTable & "Thread.Thread_ID DESC"
'mySQL limit operator
If strDatabaseType = "mySQL" Then
strSQL = strSQL & " LIMIT " & intLatestPostsMaxNo
End If
strSQL = strSQL & ";"