Author's Last 3 Topics In Topic.asp - Postet den (624 Views)
Junior Member
ILLHILL
Innlegg: 341
341
I'm trying on getting the last 3 topics to show up as links
in a person's post. So when an author writes something interesting
the reader can click on the last 3 topics started by this author.
However, the links show up but also contain the author's replies
instead of only his started topics.
I know it has to do with the Join part in here:

'## Forum_SQL - Find all records for the member
strsql = "SELECT F.FORUM_ID"
strSql = strSql & ", T.TOPIC_ID"
strSql = strSql & ", T.T_DATE"
strSql = strSql & ", T.T_SUBJECT"
strSql = strSql & ", T.T_MESSAGE"
strSql = strSql & ", T.T_STATUS"
strSql = strSql & ", T.T_LAST_POST"
strSql = strSql & " FROM ((" & strTablePrefix & "FORUM F LEFT JOIN " & strTablePrefix & "TOPICS T"
strSql = strSql & " ON F.FORUM_ID = T.FORUM_ID) LEFT JOIN " & strTablePrefix & "REPLY R"
strSql = strSql & " ON T.TOPIC_ID = R.TOPIC_ID) "
strSql = strSql & " WHERE (T_DATE > '" & strStartDate & "') "
strSql = strSql & " AND (T.T_AUTHOR = " & TMember_ID
strSql = strSql & " OR R.R_AUTHOR = " & TMember_ID & ")"
strSql = strSql & " AND (T_STATUS < 2 OR T_STATUS = 0)"
strSql = strSql & " AND F.F_TYPE = 0"
strSql = strSql & " ORDER BY T.TOPIC_ID DESC"

Everytime I experiment with the Left Join part it bugs out on me. Can anybody show me the way?
Thanks in advance, Dominic
<
   
 Sidestørrelse 
Postet den
Forum Moderator
AnonJr
Innlegg: 5768
5768
If I'm remembering right, the initial post is in the topics table and all replies are in the reply table... if that's right then I'd think you wouldn't need the reply table in the query to show just the topics they started....
But I'd get some confirmation on that first part before I took my word for it... I'm not exactly working at 100% today.<
Postet den
Junior Member
ILLHILL
Innlegg: 341
341
Any idea how I would do this? The moment I start messing with it it results in:
Syntax error in JOIN operation

<
Postet den
Junior Member
ILLHILL
Innlegg: 341
341
I tried this:

'## Forum_SQL - Find all records for the member
strsql = "SELECT F.FORUM_ID"
strSql = strSql & ", T.TOPIC_ID"
strSql = strSql & ", T.T_DATE"
strSql = strSql & ", T.T_SUBJECT"
strSql = strSql & ", T.T_STATUS"
strSql = strSql & ", T.T_LAST_POST"
strSql = strSql & " FROM " & strTablePrefix & "TOPICS T"
strSql = strSql & " WHERE T_DATE > " & strStartDate
strSql = strSql & " AND T.T_AUTHOR = " & TMember_ID
strSql = strSql & " AND T_STATUS < " & 2
strSql = strSql & " ORDER BY T.TOPIC_ID DESC"

But no luck.
Anybody knows how to do this?
Thanks, D<
Postet den
Advanced Member
Etymon
Innlegg: 2396
2396
In your SELECT statement, you'll have to add the term TOP 3 so the query will select the top (or first) 3 in the order you specify (either ascending or descending).
It needs to looks something like this:

strSql = "SELECT TOP 3 TOPIC_ID FROM " & strTablePrefix & "TOPICS WHERE T_AUTHOR = " & TMember_ID & " ORDER BY TOPIC_ID DESC"

or

strSql = "SELECT TOP 3 T.TOPIC_ID FROM " & strTablePrefix & "TOPICS T WHERE T.T_AUTHOR = " & TMember_ID & " ORDER BY T.TOPIC_ID DESC"

This query is assuming that you are seeking the first three most recent topic id's created by the author id carried in TMember_ID.<
Postet den
Junior Member
ILLHILL
Innlegg: 341
341
Got it to work! Thanks so much! One last thing. Where do I add the T.T_SUBJECT part, so I can display the topic titles as
links?
Greets & thanks again!
Dominic<
Postet den
Advanced Member
Etymon
Innlegg: 2396
2396
If your Record Set is called rs, then after you open it use

rs("T_SUBJECT")

where ever you need it or declare it, as in

Topic_Subject = rs("T_SUBJECT")

and then use

Topic_Subject

where ever you may need it. smile<
Postet den
Junior Member
ILLHILL
Innlegg: 341
341
It gives an error when I try it:

ADODB.Recordset error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name or ordinal.

Shouldn't the T.T_SUBJECT be included in the string somewhere?<
Postet den
Junior Member
ILLHILL
Innlegg: 341
341
Nevermind, solved it:

strSql = "SELECT TOP 3 T.TOPIC_ID, T.T_SUBJECT FROM " & strTablePrefix & "TOPICS T WHERE T.T_AUTHOR = " & TMember_ID & " ORDER BY T.TOPIC_ID DESC"
set rs2 = my_Conn.Execute(strsql)

Thanks so much!
Greets, Dominic
<
 
Du må legge inn en melding