Going with garys advice :) I came up with this after working out
a few problems with the mySql specific code and this has only been tested in mySql.
'## Forum_SQL - Get all topics from DB
strSql ="SELECT T.T_STATUS, T.CAT_ID, T.FORUM_ID, T.TOPIC_ID, T.T_VIEW_COUNT, T.T_SUBJECT, "
strSql = strSql & "T.T_AUTHOR, T.T_STICKY, T.T_REPLIES, T.T_UREPLIES, T.T_LAST_POST, T.T_LAST_POST_AUTHOR, "
strSql = strSql & "T.T_LAST_POST_REPLY_ID, M.M_NAME, MEMBERS_1.M_NAME AS LAST_POST_AUTHOR_NAME "
strSql = strSql & ", COUNT(R.R_AUTHOR) AS REPLIES "
strSql2 = " FROM " & strMemberTablePrefix & "MEMBERS M, "
strSql2 = strSql2 & strActivePrefix & "TOPICS T, "
strSql2 = strSql2 & strMemberTablePrefix & "MEMBERS AS MEMBERS_1 "
strSql6 = "LEFT JOIN " & strActivePrefix & "REPLY R "
strSql6 = strSql6 & "ON T.TOPIC_ID = R.TOPIC_ID AND R.R_AUTHOR = " & MemberID & " "
strSql3 = " WHERE M.MEMBER_ID = T.T_AUTHOR "
strSql3 = strSql3 & " AND T.T_LAST_POST_AUTHOR = MEMBERS_1.MEMBER_ID "
strSql3 = strSql3 & " AND T.FORUM_ID = " & Forum_ID & " "
if nDays = "-1" then
if strStickyTopic = "1" then
strSql3 = strSql3 & " AND (T.T_STATUS <> 0 OR T.T_STICKY = 1)"
else
strSql3 = strSql3 & " AND T.T_STATUS <> 0 "
end if
end if
if nDays > "0" then
if strStickyTopic = "1" then
strSql3 = strSql3 & " AND (T.T_LAST_POST > '" & defDate & "' OR T.T_STICKY = 1)"
else
strSql3 = strSql3 & " AND T.T_LAST_POST > '" & defDate & "'"
end if
end if
' DEM --> if not a Moderator, all unapproved posts should not be viewed.
if AdminAllowed = 0 then
strSql3 = strSql3 & " AND ((T.T_AUTHOR <> " & MemberID
strSql3 = strSql3 & " AND T.T_STATUS < " ' Ignore unapproved/rejected posts
if Moderation = "Y" then
strSql3 = strSql3 & "2" ' Ignore unapproved posts
else
strSql3 = strSql3 & "3" ' Ignore any hold posts
end if
strSql3 = strSql3 & ") OR T.T_AUTHOR = " & MemberID & ")"
end if
strSql7 = " GROUP BY T.TOPIC_ID"
strSql7 = strSql7 & " HAVING COUNT(R.R_AUTHOR) > -1"
strSql4 = " ORDER BY"
if strStickyTopic = "1" then
strSql4 = strSql4 & " T.T_STICKY DESC, "
end if
if strtopicsortfld = "author" then
strSql4 = strSql4 & " M." & strSortCol & " "
else
strSql4 = strSql4 & " T." & strSortCol & " "
end if
if strDBType = "mysql" then 'MySql specific code
if mypage > 1 then
intOffset = cLng((mypage-1) * strPageSize)
strSql5 = strSql5 & " LIMIT " & intOffset & ", " & strPageSize & " "
end if
'## Forum_SQL - Get the total pagecount
strSql1 = "SELECT COUNT(T.TOPIC_ID) AS PAGECOUNT "
set rsCount = my_Conn.Execute(strSql1 & strSql2 & strSql3)
iPageTotal = rsCount(0).value
rsCount.close
set rsCount = nothing
If iPageTotal > 0 then
inttotaltopics = iPageTotal
maxpages = (iPageTotal \ strPageSize )
if iPageTotal mod strPageSize <> 0 then
maxpages = maxpages + 1
end if
if iPageTotal < (strPageSize + 1) then
intGetRows = iPageTotal
elseif (mypage * strPageSize) > iPageTotal then
intGetRows = strPageSize - ((mypage * strPageSize) - iPageTotal)
else
intGetRows = strPageSize
end if
else
iPageTotal = 0
inttotaltopics = iPageTotal
maxpages = 0
end if
if iPageTotal > 0 then
set rs = Server.CreateObject("ADODB.Recordset")
rs.open strSql & strSql2 & strSql6 & strSql3 & strSql7 & strSql4 & strSql5, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText
arrTopicData = rs.GetRows(intGetRows)
iTopicCount = UBound(arrTopicData, 2)
rs.close
set rs = nothing
else
iTopicCount = ""
end if
else 'end MySql specific code
set rs = Server.CreateObject("ADODB.Recordset")
rs.cachesize = strPageSize
rs.open strSql & strSql2 & strSql6 & strSql3 & strSql7 & strSql4, my_Conn, adOpenStatic
if not rs.EOF then
rs.movefirst
rs.pagesize = strPageSize
inttotaltopics = cLng(rs.recordcount)
rs.absolutepage = mypage '**
maxpages = cLng(rs.pagecount)
arrTopicData = rs.GetRows(strPageSize)
iTopicCount = UBound(arrTopicData, 2)
else
iTopicCount = ""
inttotaltopics = 0
end if
rs.Close
set rs = nothing
end if
<