Author |
Topic |
GauravBhabu
Advanced Member
4288 Posts |
Posted - 27 September 2002 : 16:40:31
|
Code abstract from topic.asp
if mypage = -1 and Request.QueryString("REPLY_ID") <> "" then
strSql1 = "SELECT REPLY_ID "
strSql2 = "FROM " & strActivePrefix & "REPLY "
strSql3 = "WHERE TOPIC_ID = " & Topic_ID & " "
...
...
Response.Redirect("topic.asp?" & strwhichpage & "TOPIC_ID=" & Topic_ID & "#" & LastPostReplyID & "")
Response.End
end if
This code block in topic.asp when executed redirects to topic.asp after processing. However this is done after quering the database and initializing about 50 variables.
Unless there is a reason which I can not think of, I think this code can be put in lastpost.asp from where it may be redirected to topic.asp or it can be moved up in topic.asp.
Okay I see the reason for this code to be where it is. Variables Admin Allowed and Moderation are populated on the basis of information retreived from the database.
Bookmark is also added to the URL when redirecting. However, If bookmark is added to the URL at link level it will save a trip to server and database. |
Edited by - GauravBhabu on 27 September 2002 17:44:31 |
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 27 September 2002 : 18:05:18
|
This is what I would like to suggest.
Move the code within the following if then endif to a function (function returns the page number on which the reply is found.) The statement in red gets the page number
if mypage = -1 and Request.QueryString("REPLY_ID") <> "" then
myPage = LastPostPage()
end if
function LastPostPage()
dim strReplyStatus, intPageNumber
dim strSql1, strSql2, strSql3, strSql4
dim LastPostReplyID, rsReplies, arrReplyData
dim iReplyCount, rREPLY_ID, iReply, intReplyID
intPageNumber = 1
if Moderation = "Y" then
Rem -Ignore unapproved/rejected posts
strReplyStatus = "2"
else
Rem -Ignore any previously rejected topic
strReplyStatus = "3"
end if
LastPostReplyID = cLng(Request.QueryString("REPLY_ID"))
strSql1 = "SELECT REPLY_ID "
strSql2 = "FROM " & strActivePrefix & "REPLY "
strSql3 = "WHERE TOPIC_ID = " & Topic_ID
if AdminAllowed = 0 then
strSql3 = strSql3 & " AND (R_STATUS < " & strReplyStatus
strSql3 = strSql3 & " OR R_AUTHOR = " & MemberID & ")"
end if
strSql4 = " ORDER BY R_DATE ASC "
set rsReplies = Server.CreateObject("ADODB.Recordset")
if strDBType = "mysql" then
rsReplies.open strSql1 & strSql2 & strSql3 & strSql4, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText
else
rsReplies.cachesize = strPageSize
rsReplies.pagesize = strPageSize
rsReplies.open strSql1 & strSql2 & strSql3 & strSql4, my_Conn, adOpenStatic, adLockReadOnly, adCmdText
end if
if not (rsReplies.EOF or rsReplies.BOF) then
if strDBType = "mysql" then
arrReplyData = rsReplies.GetRows(adGetRowsRest)
iReplyCount = UBound(arrReplyData, 2)
rREPLY_ID = 0
for iReply = 0 to iReplyCount
intReplyID = arrReplyData(rREPLY_ID,iReply)
if LastPostReplyID = intReplyID then
intPageNumber = ((iReply+1)/strPageSize)
if intPageNumber > cLng(intPageNumber) then
intPageNumber = cLng(intPageNumber) + 1
exit for
end if
end if
next
else
rsReplies.Find = "REPLY_ID=" & LastPostReplyID & ""
if not (rsReplies.EOF or rsReplies.BOF) then
if rsReplies.absolutepage > 1 then intPageNumber = rsReplies.absolutepage
end if
end if
end if
rsReplies.Close
set rsReplies = nothing
LastPostPage = intPageNumber
end function
This will also require modifications in default.asp, forum.asp and active.asp. The bookmark will need to be added to the URL at the link level. Like as shown below.
http://forum.snitz.com/forum/topic.asp?whichpage=-1&TOPIC_ID=35891&REPLY_ID=180407𬂷
|
|
|
burthold
Junior Member
USA
426 Posts |
Posted - 27 September 2002 : 18:38:23
|
So, all this is to save one trip to the database yes? I'm just trying to grasp the entire empact on speed and/or forum function. I think it is a very eligant way to handle it. You are a true coding guru. Is there a reason to use a bookmark over getrows even if we aren't using MySQL? |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 27 September 2002 : 18:47:54
|
There is also no need of whichpage=-1 in the URL.
A URL like this will also work
http://forum.snitz.com/forum/topic.asp?TOPIC_ID=35891&REPLY_ID=180407𬂷
In this case a little modification to the code posted above will be require as below
if Request.QueryString("REPLY_ID") <> "" then
myPage = LastPostPage()
end if
The changes in active.asp, forum.asp, default.asp will be required in the function DOLastPostLink
Example from default.asp
DoLastPostLink = "<a href=""topic.asp?" & "TOPIC_ID=" & ForumLastPostTopicID & AnchorLink & ForumLastPostReplyID & "#" & ForumLastPostReplyID & """>" |
|
|
work mule
Senior Member
USA
1358 Posts |
Posted - 27 September 2002 : 22:51:07
|
(...are you ready for this??)
There are 3 options for this....
Option 1: Link to the Last Post Option 2: Link to the First New Post (First Unread Post) Option 3: Allow for links to Replies (via bookmarks)
@ FORUM.ASP
Function DoLastPostLink()
if Topic_Replies < 1 or Topic_LastPostReplyID = 0 then
DoLastPostLink = "<a href=""topic.asp?" & ArchiveLink & "TOPIC_ID=" & Topic_ID & """>" & _
getCurrentIcon(strIconLastpost,"Jump to Last Post","align=""absmiddle""") & "</a>"
elseif Topic_LastPostReplyID <> 0 then
PageLink = "whichpage=-1&"
AnchorLink = "&REPLY_ID="
DoLastPostLink = "<a href=""topic.asp?" & ArchiveLink & PageLink & "TOPIC_ID=" & Topic_ID & AnchorLink & Topic_LastPostReplyID & """>" & _
getCurrentIcon(strIconLastpost,"Jump to Last Post","align=""absmiddle""") & "</a>"
else
DoLastPostLink = ""
end if
end function
The link built in DoLastPostLink doesn't need to include the REPLY_ID for the record.
It's simple really... For Option 1, add "&jump=lastpost" to the querystring and a bookmark of "#lastpost". For Option 2, add "&jump=newpost" to the querystring and a bookmark of "#newpost".
Function DoLastPostLink()
DoLastPostLink = "<a href=""topic.asp?" & ArchiveLink & "TOPIC_ID=" & Topic_ID & "&jump=lastpost#lastpost"">" & _
getCurrentIcon(strIconLastpost,"Jump to Last Post","align=""absmiddle""") & "</a>"
end function
- or -
Function DoNewPostLink()
DoNewPostLink = "<a href=""topic.asp?" & ArchiveLink & "TOPIC_ID=" & Topic_ID & "&jump=newpost#newpost"">" & _
getCurrentIcon(strIconLastpost,"Jump to Unread Post","align=""absmiddle""") & "</a>"
end function
In the case where there are no replies to a topic, it doesn't matter. The bookmark tag won't be written out in topic.asp, thus there wouldn't be a match for either options' bookmark.
@ TOPIC.ASP Okay, the link is clicked on and a request is made for topic.asp.
We need to check the value of jump (lastpost, newpost or nothing).
So going back to that block of code that GauravBhabu referenced before:
if mypage = -1 and Request.QueryString("REPLY_ID") <> "" then
strSql1 = "SELECT REPLY_ID "
strSql2 = "FROM " & strActivePrefix & "REPLY "
strSql3 = "WHERE TOPIC_ID = " & Topic_ID & " "
...
...
Response.Redirect("topic.asp?" & strwhichpage & "TOPIC_ID=" & Topic_ID & "#" & LastPostReplyID & "")
Response.End
end if
We can change that block of code to something like this:
Dim strJumpTo, intJumpToID
strJumpTo = Trim(Request.QueryString("jump"))
if strJumpTo <> "" then SetJumpParameters strJumpTo
Add the following sub to topic.asp:
Sub SetJumpParameters(jump)
Dim strSql1, strSql2, strSql3, intReplyCount
Select Case jump
Case "lastpost"
strSql1 = "SELECT COUNT(REPLY_ID) AS ReplyCount, MAX(REPLY_ID) AS ReplyID "
strSql3 = "WHERE (TOPIC_ID = " & Topic_ID & ") "
Case "newpost"
strSql1 = "SELECT COUNT(REPLY_ID) AS ReplyCount, MIN(REPLY_ID) AS ReplyID "
strSql3 = "WHERE (TOPIC_ID = " & Topic_ID & ") AND (R_DATE > '" & Session(strCookieURL & "last_here_date") & "') "
Case "replyid"
strSql1 = "SELECT COUNT(REPLY_ID) AS ReplyCount, MAX(REPLY_ID) AS ReplyID "
strSql3 = "WHERE (TOPIC_ID = " & Topic_ID & ") AND (REPLY_ID = " & Request.QueryString("REPLY_ID") & ") "
Case Else
exit sub 'doesn't match
End Select
strSql2 = "FROM " & strActivePrefix & "FORUM_REPLY "
' DEM --> if not a Moderator, all unapproved posts should not be viewed.
if AdminAllowed = 0 then
strSql3 = strSql3 & "AND (R_STATUS < "
if Moderation = "Y" then
' Ignore unapproved/rejected posts
strSql3 = strSql3 & "2 "
else
' Ignore any previously rejected topic
strSql3 = strSql3 & "3 "
end if
strSql3 = strSql3 & "OR R_AUTHOR = " & MemberID & ") "
end if
set rsReplies = Server.CreateObject("ADODB.Recordset")
rsReplies.open strSql1 & strSql2 & strSql3, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText
if rsReplies.EOF then
'iReplyCount = ""
else
intReplyCount = rsReplies(0)
intJumpToID = rsReplies(1)
end if
rsReplies.Close
set rsReplies = nothing
Select Case jump
Case "lastpost"
intPageNumber = ((intReplyCount)/strPageSize)
Case "newpost"
intPageNumber = (((Topic_Replies-intReplyCount)+1)/strPageSize)
Case "replyid"
intPageNumber = ((Topic_Replies-intReplyCount)/strPageSize)
End Select
if intPageNumber > cLng(intPageNumber) then
intPageNumber = cLng(intPageNumber) + 1
end if
mypage = intPageNumber
End Sub
...with that out of the way, we don't need to redirect since we have the correct value of mypage and we also know what the reply_id we're looking for.
Further down the page (topic.asp), we'll look for the matching REPLY_ID.
If Reply_ReplyID = intJumpToID Then
Response.Write "<a name=""" & strJumpTo & """></a>"
End If
Important thing to note here is that we're using generic bookmark labels. When the page renders out, the correct page of replies will be displayed. One of those replies (=intJumpToID) will have the generic bookmark label and the browser will take the user right to the bookmark (unless it's a small page and it can't scroll).
Oh, going back to linking directly to a reply, the link would look like this:
Function DoDirectPostLink(id)
DoDirectPostLink = "<a href=""topic.asp?" & ArchiveLink & "TOPIC_ID=" & Topic_ID & "&REPLY_ID=" & id & "&jump=replyid#replyid"">" & _
getCurrentIcon(strIconLastpost,"Jump to This Post","align=""absmiddle""") & "</a>"
end function
|
|
|
work mule
Senior Member
USA
1358 Posts |
Posted - 27 September 2002 : 22:57:24
|
reference posts...
"jump to first unread message" button http://forum.snitz.com/forum/topic.asp?ARCHIVE=true&TOPIC_ID=9756
MOD: (Jump to) 1st New Post & Last Post of Topic http://forum.snitz.com/forum/topic.asp?ARCHIVE=true&TOPIC_ID=10231
In that mod, there was a black arrow (similiar to current Snitz) to take people to the last post in the thread. There was also an additional blue arrow that would appear before the topic subject/name (on forum.asp) to take people to the 1st new post in that thread (if there were any).
With the above code we could take care of both situations.
|
Edited by - work mule on 27 September 2002 22:58:23 |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 28 September 2002 : 01:53:34
|
work mule II, there are more options with your suggestion. I was mainly thinking...why Redirect?
However, the way jump to last post works as of now is it links to the last post which is last posted or last edited. so with your suggestions above that functionality will be lost in part as it will not link to last edited post.
------------------------------------------------------------------------ And also to note is:
There is a field in Topics table which store the lastpostid information
T_LAST_POST_REPLY_ID
There are fields in Forum table which store the lasttopicid and lastpostid
F_LAST_POST_TOPIC_ID F_LAST_POST_REPLY_ID
The values for these fields are updated whenever a post is edited ---------------------------------------------------------------------------- |
Edited by - GauravBhabu on 28 September 2002 02:03:23 |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 28 September 2002 : 07:05:52
|
work mule II the sql for case "replyid" will return only one record |
|
|
work mule
Senior Member
USA
1358 Posts |
Posted - 28 September 2002 : 16:01:00
|
quote: Originally posted by GauravBhabu
work mule II, there are more options with your suggestion. I was mainly thinking...why Redirect?
However, the way jump to last post works as of now is it links to the last post which is last posted or last edited. so with your suggestions above that functionality will be lost in part as it will not link to last edited post.
Yeah, I definitely agree that the redirect isn't needed. There are ways to avoid having to do it. I didn't even think about looking into it until I saw your post.
I guess I was making the assumption that "Last Post" would literally be the last post in a topic.
In regards to the SQL for the "replyid", I guess it would only return one record. Silly me.
In the case of the replyid, I don't care about the actual id being selected - I already know the id. I included it in the SQL statement to be consistant in the sub procedure code. The important number is knowing the posting order of that post in relation to the rest of the threads. If it was post #25 and paging was set to 20, then it would be on the second page.
First thing that came to mind was this:
Case "replyid"
strSql1 = "SELECT COUNT(REPLY_ID) AS ReplyCount, MAX(REPLY_ID) AS ReplyID "
strSql3 = "WHERE (TOPIC_ID = " & Topic_ID & ") AND (REPLY_ID <= " & Request.QueryString("REPLY_ID") & ") "
The only problem with the above (and the other SQL statements) is that the id fields aren't always going to be in order. What I mean is that the autonumber/identity fields aren't always going to use the next highest number. It is possible for autonumber and identity values to be reset.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_dbcc_5lv8.asp
"Pooh," said Rabbit kindly, "You haven't any brain." "I know," said Pooh humbly. - Winnie-the-Pooh
Okay...I need to think about this a bit more. I know we can get that "magic number" without having to return a recordset of replyid's and looping through to get to that number. |
Edited by - work mule on 28 September 2002 16:11:12 |
|
|
work mule
Senior Member
USA
1358 Posts |
Posted - 28 September 2002 : 16:10:39
|
Doh!
How silly of me...
If "Last Post" is literally a link to the last post, then we don't need to query the database. We already have access to Topic_Replies which is the total number of replies (right??). So to get the pagenumber, it's simply a matter of this:
Select Case jump
Case "lastpost"
intPageNumber = (Topic_Replies/strPageSize)
However, if "Last Post" also includes last edited fields, that would still require a query vs. the database.
We could check Topic_LastEdit to see if there was an edit. If so, then run the query. If there are no edits, then do the above. |
Edited by - work mule on 28 September 2002 16:11:33 |
|
|
James
Average Member
USA
539 Posts |
Posted - 28 September 2002 : 17:07:29
|
WorkMule, are you going to post this as a mod in the mod forum? I love the idea of being able to go to the first new reply in a post. |
*Interested in Radio Control* *The RC Web Board - http://www.rcwebboard.com/* |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 28 September 2002 : 23:36:39
|
quote: Originally posted by work mule II However, if "Last Post" also includes last edited fields, that would still require a query vs. the database.
I think we already have enough info from the database to find the magic number for the last edited post...I will post after testing. |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 29 September 2002 : 01:06:58
|
"...Okay..."
Option 1, add "&jump=lastpost" to the querystring and a bookmark of "#lastpost".
Option 2, add "&jump=newpost" to the querystring and a bookmark of "#newpost".
Option 3, add "&jump=replyid" to the querystring and a bookmark of "#replyid".
Rem -Declare and initialize the variable
Dim strJumpTo, intJumpToID
strJumpTo = Trim(Request.QueryString("jump"))
if not (rsReplies.EOF or rsReplies.BOF) then
rsReplies.pagesize = strPageSize
Rem -Find the page number where the record exists
if strJumpTo <> "" then
mypage = JumpToPage(strJumpTo)
end if
rsReplies.absolutepage = mypage '**
maxpages = cLng(rsReplies.pagecount)
if maxpages >= mypage then
arrReplyData = rsReplies.GetRows(strPageSize)
iReplyCount = UBound(arrReplyData, 2)
else
iReplyCount = ""
end if
else '## No replies found in DB
iReplyCount = ""
end if
Rem -Write the bookmark:
If Reply_ReplyID = intJumpToID Then
Response.Write "<a name=""" & strJumpTo & """></a>"
End If
Rem -Returns the Page Number
function JumpToPage(jump)
dim intPageNumber
Select Case jump
Case "lastpost"
rsReplies.Find = "R_LAST_EDIT='" & Topic_LastPost & "'"
if (rsReplies.BOF or rsReplies.EOF) then
rsReplies.MoveFirst
rsReplies.Find = "R_DATE='" & Topic_LastPost & "'"
end if
Case "newpost"
rsReplies.Find = "R_DATE >'" & Session(strCookieURL & "last_here_date") & "'"
Case "replyid"
rsReplies.Find = "REPLY_ID=" & Request.QueryString("REPLY_ID")
Case else
JumpToPage = myPage
exit sub
end select
if not (rsReplies.BOF or rsReplies.EOF) then
intPageNumber = rsReplies.absolutepage
intJumpToID = rsReplies("REPLY_ID")
end if
rsReplies.MoveFirst
if intPageNumber <= 0 then intPageNumber = myPage
JumpToPage = intPageNumber
End function
Rem -Build the Links
Function DoLastPostLink()
DoLastPostLink = "<a href=""topic.asp?" & ArchiveLink & "TOPIC_ID=" & Topic_ID & "&jump=lastpost#lastpost"">" & _
getCurrentIcon(strIconLastpost,"Jump to Last Post","align=""absmiddle""") & "</a>"
end function
- or -
Function DoNewPostLink()
DoNewPostLink = "<a href=""topic.asp?" & ArchiveLink & "TOPIC_ID=" & Topic_ID & "&jump=newpost#newpost"">" & _
getCurrentIcon(strIconLastpost,"Jump to Unread Post","align=""absmiddle""") & "</a>"
end function
- or -
Function DoDirectPostLink(id)
DoDirectPostLink = "<a href=""topic.asp?" & ArchiveLink & "TOPIC_ID=" & Topic_ID & "&REPLY_ID=" & id & "&jump=replyid#replyid"">" & _
getCurrentIcon(strIconLastpost,"Jump to This Post","align=""absmiddle""") & "</a>"
end function
|
Edited by - GauravBhabu on 29 September 2002 06:14:58 |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 29 September 2002 : 01:42:33
|
It works great. I will package it as a Mod with complete details. |
|
|
DoraMoon
Average Member
Taiwan
661 Posts |
Posted - 29 September 2002 : 06:49:21
|
quote: Originally posted by GauravBhabu
It works great. I will package it as a Mod with complete details.
It's Great !! i just wonder where i should put these code on ???
Expect this great Mod eagerly.... |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 29 September 2002 : 07:49:23
|
I am writting the details, will post in Mods Forum. |
|
|
Topic |
|