Udtræk af nyeste post
Jeg er igang med at lave et forum, det går egentligt fint nok og jeg har prøvet at udtrække datoen på den nyeste post og hvem der har postet med 1 SQL streng.Hele koden er her nede under:
<%
'-----------------------
'-------- FORUM --------
'-----------------------
Dim rsForum 'Holds the Recordset for the forum details
Dim rsThreads 'Holds the recordset for the thread details
Dim ForumID 'Holds the forum ID number
Dim LastEntryDate 'Holds the date of the last entry to the forum
Dim LastEntryUser 'Holds the the username of the user who made the last entry
Dim LastEntryUserID 'Holds the ID number of the last user to make and entry
Set forumtemp = Server.CreateObject("ADoDB.Connection")
DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath("../../db/clan_ld_db_new.mdb")
forumtemp.open DSN
SQLFORUM = "SELECT * FROM Forums"
Set rsForum = forumtemp.execute(SQLFORUM)
If Not (rsForum.BOF or rsForum.EOF) Then
Response.Write "<td align=""center"" valign=""top"" height=""135"" width=""425"" background=""design/Middle.jpg"">"
Response.Write "<font color=""#000000"" face=""verdana"" size=""2""><br><br><br><br><br><br><br><br><br><br><br><b>Forum</b></font></td>"
Response.Write "<td align=""left"" valign=""top"" height=""135"" colspan=""3"">"
Response.Write "<img src=""design/Right.jpg"" width=""103"" height=""199""></td></tr>"
Response.Write "<tr>"
Response.Write "<td align=""left"" valign=""top"" width=""31""> </td>"
Response.Write "<td align=""left"" valign=""top"" width=""16""><img src=""gIf/pixel.gIf"" width=""1"" height=""1""></td>"
Response.Write "<td align=""left"" valign=""top"" background=""gIf/dims2B.gIf"" width=""12""> </td>"
Response.Write "<td align=""left"" valign=""top"" width=""425"" bgcolor=""C5C5C5""><br>"
'----------------------------
'-------- FORUM MENU --------
'----------------------------
SQLTOTALT = "SELECT COUNT(TID) AS CountTotalT FROM F_threads" '---- TÆLLER ANTAL THREADS IALT
Set rsTotalT = forumtemp.execute(SQLTOTALT)
SQLTOTALP = "SELECT COUNT(RID) AS CountTotalP FROM F_Replies" '---- TÆLLER ANTAL POSTS IALT
Set rsTotalP = forumtemp.execute(SQLTOTALP)
Response.Write "<table border=""0"" align=""center"" cellpadding=""0"" cellspacing=""0"" width=""425""><tr><td>"
Response.Write "<table style=""border: 1 solid #000000"" align=""center"" border=""0"" cellpadding=""0"" cellspacing=""0"" width=""400""><tr>"
Response.Write "<td width=""100%"" valign=""top""><font color=""#000000""><b>Total threads: "& rsTotalT("CountTotalT") &"</b> - <b>Total Posts: "& rsTotalP("CountTotalP") &"</b></font></td>"
Response.Write "</tr></table></td></tr></table><br>"
'--------------------------------
'-------- FORUM OVERVIEW --------
'--------------------------------
Response.Write "<table border=""0"" cellpadding=""0"" cellspacing=""0"" width=""425""><tr><td>"
Response.Write "<table style=""border: 1 solid #000000"" align=""center"" border=""0"" cellpadding=""0"" cellspacing=""0"" width=""400""><tr>"
Response.Write "<td width=""53%"" align=""center"" valign=""top"" bgcolor=""#E8E8E8""><font color=""#000000""><b>Forums</b></font></td>"
Response.Write "<td width=""35%"" align=""center"" valign=""top"" bgcolor=""#E8E8E8""><font color=""#000000""><b>Last post</b></font<</td>"
Response.Write "<td width=""22%"" align=""center"" valign=""top"" bgcolor=""#E8E8E8""><font color=""#000000""><b>Threads</b></font></td>"
Response.Write "</tr></table></td></tr></table>"
Do While Not rsForum.EOF
ForumID = CInt(rsForum("ID"))
Conntemp = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&Server.MapPath("../../db/clan_ld_db_new.mdb")
Set rsThread = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT TOP 1 F_Replies.R_Date, Users.Alias, Users.UsrID "
strSQL = strSQL & "FROM (Forums INNER JOIN F_Threads ON Forums.ID = F_Threads.FID) INNER JOIN (Users INNER JOIN F_Replies ON Users.UsrID = F_Replies.UsrID) ON F_Threads.TID = F_Replies.TID "
strSQL = strSQL & "WHERE F_Threads.FID = " & ForumID & " "
strSQL = strSQL & "ORDER BY F_Replies.R_Date DESC;"
Response.Write strSQL
rsThread.Open strSQL, Conntemp
If Not rsThread.EOF Then
LastEntryDate = CDate(rsThread("R_Date"))
LastEntryUser = rsThread("Alias")
LastEntryUserID = CLng(rsThread("UsrID"))
SQLthreadS = "SELECT COUNT(TID) AS Countthreads FROM F_threads WHERE (FID = "& rsForum("ID") &")" 'TÆLLER ANTAL THREADS FOR HVERT FORUM
Set rsthreads = forumtemp.execute(SQLthreadS)
End If
Response.Write "<table border=""0"" cellpadding=""0"" cellspacing=""0"" width=""425""><tr><td>"
Response.Write "<table style=""border-left: 1 solid #000000; border-right: 1 solid #000000; border-bottom: 1 solid #000000"" align=""center"" border=""0"" cellpadding=""0"" cellspacing=""0"" width=""400""><tr>"
Response.Write "<td width=""53%"" style=""border-right: 1 solid #000000"" valign=""top""><a href=""threads.asp?ID="& rsForum("ID") &"""><b>"& rsForum("F_Name") &"</b></a><br>"& rsForum("F_Description") &"</td>"
Response.Write "<td width=""35%"" style=""border-right: 1 solid #000000"" align=""center"" valign=""top"">"& LastEntryDate &"<br>"& LastEntryUser &"</td>"
Response.Write "<td width=""22%"" align=""center"" valign=""top"">"& rsthreads("Countthreads") &"</td>"
Response.Write "</tr></table></td></tr></table>"
rsForum.movenext
Loop
rsthreads.Close : Set rsthreads = Nothing : rsForum.Close : Set rsForum = Nothing
End If
%>
Fejlen kan i se på www.limitless.dk/test/forum.asp
Linien hvor fejlen er i, er her nedenunder:
strSQL = "SELECT TOP 1 F_Replies.R_Date, Users.Alias, Users.UsrID "
strSQL = strSQL & "FROM (Forums INNER JOIN F_Threads ON Forums.ID = F_Threads.FID) INNER JOIN (Users INNER JOIN F_Replies ON Users.UsrID = F_Replies.UsrID) ON F_Threads.TID = F_Replies.TID "
strSQL = strSQL & "WHERE F_Threads.FID = " & ForumID & " "
strSQL = strSQL & "ORDER BY F_Replies.R_Date DESC;"
Har spørgsmål kan i bare spørge.
På forhånd tak!
