Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/59539?pagenum=1
05 November 2025, 09:51
Topic
Shaggy
Jump to Last Post Permalink
21 September 2005, 13:05
After some recent discussions about it, I've been working on modifying the jump to last post feature so it does not need to pass the REPLY_ID through the querystring, effectively allowing you to create permanent links that will always take you to the latest post in a topic. Here's what I have so far:
Code:
if mypage=-1 then strSql1="SELECT REPLY_ID" strSql2=" FROM "&strActivePrefix&"REPLY " strSql3=" WHERE TOPIC_ID="&Topic_ID if AdminAllowed=0 then strSql3=strSql3&" AND (R_STATUS<" if Moderation="Y" then strSql3=strSql3&"2" else strSql3=strSql3&"3" 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,adOpenStatic,adLockReadOnly,adCmdText if rsReplies.eof then iReplyCount=-1 strwhichpage="" else arrReplyData=rsReplies.getrows(adGetRowsRest) iReplyCount=ubound(arrReplyData,2) if len(request.querystring("REPLY_ID"))>0 then LastPostReplyID=clng(request.querystring("REPLY_ID")) else LastPostReplyID=cLng(arrReplyData(0,iReplyCount)) end if if iReplyCount>-1 then for iReply=0 to iReplyCount intReplyID=arrReplyData(0,iReply) if LastPostReplyID=intReplyID then intPageNumber=((iReply+1)/strPageSize) if intPageNumber>clng(intPageNumber) then intPageNumber=clng(intPageNumber)+1 strwhichpage="whichpage="&intPageNumber&"&" exit for end if next end if else rsReplies.cachesize=strPageSize rsReplies.pagesize=strPageSize rsReplies.open strSql1&strSql2&strSql3&strSql4,my_Conn,adOpenStatic,,adCmdText
if len(request.querystring("REPLY_ID"))>0 then LastPostReplyID=clng(request.querystring("REPLY_ID")) else rsReplies.movelast LastPostReplyID=cLng(rsReplies("REPLY_ID")) rsReplies.movefirst end if
rsReplies.find="REPLY_ID="&LastPostReplyID&"" if not (rsReplies.eof or rsReplies.bof) then if rsReplies.absolutepage>1 then strwhichpage="whichpage="&rsReplies.absolutepage&"&" else strwhichpage = "" end if end if rsReplies.close set rsReplies=nothing my_Conn.close set my_Conn=nothing response.redirect("topic.asp?"&strwhichpage&"TOPIC_ID="&Topic_ID&"#"&LastPostReplyID&"") response.end end if
That replaces the if statement beginning on line 202 of a fresh, v3.4.05 topic.asp. Note that I haven't tested this yet mainly because I don't have a clean Snitz that I can test it on but also because I've already encountered a problem in that the code above will always take you to the last actual reply to a topic without taking into account any replies that may have been edited after the last actual reply. I'm about to switch over to me other job for the evening but wanted to post this here first so's ye could see where I'm going with it and maybe offer some insights as to how to get around the problem I mentioned.
<
Replies ...
Shaggy
22 September 2005, 06:54
Actually, thinking about it las night, would it really be that big a deal if this script redirected you to the last actual reply in a topic rather than the last edited reply? The main purpose for this script is for external links, which people unfamiliar with Snitz would be expecting to take them to the last actual post, and subscription mails which will only get sent out upon a new post.
All I need now is someone with a base install to test the above for me <
Riccardo
22 September 2005, 08:24
i can test it ..but i haven't a fresh or new topic.asp<
Shaggy
22 September 2005, 08:25
Cool, cheers, man Be sure to back up your topic.asp file first, of course.
<
Riccardo
22 September 2005, 08:35
ok tested..but i don't see big differences from the regular work of topic.asp could you explain me better the purpose of that code?<
Shaggy
22 September 2005, 08:48
Instead of linking to the last post of a topic using topic.asp?TOPIC_ID=x&whichpage=-1&REPLY_ID=y which will bring you to a specified reply (y), you can now do so using topic.asp?TOPIC_ID=x&whichpage=-1 which will always bring you to the actual last reply made in a topic.
<
Riccardo
22 September 2005, 08:52
so you save time for this operation now? anyway the code work perfectly. Tested with reply and notifications..<
Shaggy
22 September 2005, 08:53
Got a link 'til I have a look?
<edit> By the way, what database did you test it on? </edit>
<
Riccardo
22 September 2005, 08:55
yes you can..it a test forum in italian. the firts row is black 'cause i was testing a css style.
you find it here..
links removed by ruirib at user's request
Database? ACCESS<
Shaggy
22 September 2005, 09:06
D'oh! It's actually linking to the first reply. I've made some changes to me code above, in green, which should fix that.
<
Riccardo
22 September 2005, 09:13
i've modified..still the same result?
tell me 'cause i don't see differences.. :(<
Shaggy
22 September 2005, 09:16
It's working fine for me now on your test forum <
Riccardo
22 September 2005, 09:23
good..when i'll understand all differences i'll be graduated in Snitz forum testing.. <
Davio
22 September 2005, 09:25
I would think the main reason for passing it in the querystring, is to cut down on database calls. <
Riccardo
22 September 2005, 09:28
ok great..if you want to test other codes i'm here (but later)! see you..<
Shaggy
22 September 2005, 09:29
Originally posted by Davio
I would think the main reason for passing it in the querystring, is to cut down on database calls.
Ay, but my script doesn't use any additional queries, it works off the existing query in topic.asp that's used to determine the page number. <
Davio
22 September 2005, 10:17
Originally posted by Shaggy Ay, but my script doesn't use any additional queries, it works off the existing query in topic.asp that's used to determine the page number.
Ay, good job then! <
Shaggy
22 September 2005, 10:20
Although, I seem to remember someone once telling me that jumping around recordsets using the likes of movefirst and movelast isn't exactly an ideal way to work so there may be room for improvement there.
Does anyone have a clean version of Snitz running of MSSQL or MySQL that they could test this on to be sure it works?
<
ruirib
22 September 2005, 10:36
I can give it a try later on. I always have several Snitz versions installed locally, and now I even have MySQL installed as well...<
Shaggy
22 September 2005, 10:38
Thanks, Rui Really must get a couple of test forums up & running meself now that I can do so on the new server.
<
net83it
24 September 2005, 12:50
Originally posted by Riccardo yes you can..it a test forum in italian. the firts row is black 'cause i was testing a css style.
links removed by ruirib at user's request
i get always the default.asp page when i click the last reply arrow.
see the difference links removed by ruirib at user's request
i also tested the script on my 3.4.03 and i get the same error!
so it seems it doesn't work! :(<
ruirib
24 September 2005, 13:39
net83bit, you need to be running an OLEDB driver for the jump to work. What is your current connection string (remove username/password if that is the case)?<
Riccardo
24 September 2005, 13:51
My forum isn't a test one..
Ruy please delete all links to my forum from this topic..thanks<
ruirib
24 September 2005, 16:21
Links deleted.<
ruirib
24 September 2005, 16:52
Shaggy, this didn't work with SQL Server. A redirect to default.asp occurs. Normal topic.asp works without a hitch.<
net83it
25 September 2005, 06:18
i'm using mysql<
Shaggy
26 September 2005, 07:09
Hmm ... Don't see why it wouldn't work with SQL Server if it works with Access. Can you check which of the redirects is being executed?
Also, was thinking about improvements to this over the weekend and got to wondering why Access and MSSQL don't use the same code as MySQL for determining the page number so I came up with this:
Code:
if mypage=-1 then strSql="SELECT REPLY_ID FROM "&strActivePrefix&"REPLY WHERE TOPIC_ID="&Topic_ID if AdminAllowed=0 then strSql=strSql&" AND (R_STATUS<" if Moderation="Y" then strSql=strSql&"2" else strSql=strSql&"3" strSql=strSql&" OR R_AUTHOR="&MemberID&")" end if strSql=strSql&" ORDER BY R_DATE ASC" set rsReplies=server.createobject("ADODB.Recordset") rsReplies.open strSql,my_Conn,adOpenStatic,adLockReadOnly,adCmdText if not rsReplies.eof then arrReplyData=rsReplies.getrows(adGetRowsRest) iReplyCount=ubound(arrReplyData,2) if len(request.querystring("REPLY_ID"))>0 then LastPostReplyID=clng(request.querystring("REPLY_ID")) for iReply=0 to iReplyCount intReplyID=arrReplyData(0,iReply) if LastPostReplyID=intReplyID then intPageNumber=((iReply+1)/strPageSize) if intPageNumber>clng(intPageNumber) then intPageNumber=clng(intPageNumber)+1 strwhichpage="whichpage="&intPageNumber&"&" exit for end if next else LastPostReplyID=arrReplyData(0,iReplyCount) intPageNumber=((iReplyCount+1)/strPageSize) if intPageNumber>clng(intPageNumber) then intPageNumber=clng(intPageNumber)+1 strwhichpage="whichpage="&intPageNumber&"&" end if else strWhichpage="" end if rsReplies.close set rsReplies=nothing my_Conn.close set my_Conn=nothing response.redirect("topic.asp?"&ArchiveLink&strwhichpage&"TOPIC_ID="&Topic_ID&SearchLink"#"&LastPostReplyID&"") response.end end if
Note that I've also added ArchiveLink to the redirect URI to save an additional redirect on archived topics. And I've added the SerachLink too which will also require the search terms to be added to the querystring of the last post link in search results.
<
ruirib
26 September 2005, 14:15
Shaggy,
The code has several problems. First, near the beginning, where you have
Code:
if AdminAllowed=0 then strSql=strSql&" AND (R_STATUS<" if Moderation="Y" then strSql=strSql&"2" else strSql3=strSql3&"3" strSql=strSql&" OR R_AUTHOR="&MemberID&")"
the part in red should be strSql and not strsql3 Second, in my test forum, the redirect link is coming out like this:
topic.asp?whichpage=3.66666666666667&TOPIC_ID=1#11 <
Shaggy
27 September 2005, 06:19
Thanks, Rui; spotted the strSql3s when I got home yesterday but was just on a flying visit and didn't have time to edit.
Second problem's an odd one though as I didn't actually make any changes to the way intPageNumber is calcualted other than to use iReplyCount instead of iReply when there's no REPLY_ID in the querystring. Can you try changing:
intPageNumber=((iReply+1)/strPageSize)
To:
intPageNumber=(iReply\strPageSize)+1
And:
intPageNumber=((iReplyCount+1)/strPageSize)
To:
intPageNumber=(iReplyCount\strPageSize)+1
And see if it makes any difference?
<
ruirib
27 September 2005, 08:14
I'll do this from home, when I get there.<
Shaggy
27 September 2005, 08:22
Thanks, man <
ruirib
27 September 2005, 09:32
Ok, previous problem gone, but it still does not jump to the last page. Redirects to default.asp. Will try to figure out why later.<
Shaggy
27 September 2005, 09:43
*Scratches head* Obviously there's a typo I'm missing somewhere. A response.write on the redirect URI may reveal the problem.
<
ruirib
27 September 2005, 11:35
Originally posted by Shaggy *Scratches head* Obviously there's a typo I'm missing somewhere. A response.write on the redirect URI may reveal the problem.
I did it. Seemed ok to me. Will have to do it step by step, to find out where the redirect is ocurring.<
Shaggy
27 September 2005, 11:36
Appreciate it, Rui Sorry to be bugging you with all these tests, really gotta get around to setting up a clean test forum meself <
ruirib
27 September 2005, 11:47
No problem. Give this a bump if I forget it.<
Shaggy
29 September 2005, 06:46
Quick thought, Rui, are there any &s in the URI when you response.write it?
<
ruirib
29 September 2005, 06:52
No Shaggy, didn't find any. Hope to have a go at this tonight.<
Shaggy
29 September 2005, 07:02
Feck! Was hoping that'd be it! <
Shaggy
02 January 2006, 06:25
A quick bump for tomorrow so's I don't forget this.
<
Shaggy
07 March 2006, 10:17
Just resurrecting this one to see if anyone has any further thoughts on the problem we're encoutering above.
<
ruirib
07 March 2006, 10:24
Ah, you're ressurrecting it then .
<
ruirib
07 March 2006, 10:50
I can confirm the issue persists. Just tested it.<
ruirib
07 March 2006, 11:06
Ok, found the answer. There was a small detail missing. Here is the line that needs changing:
In red that's what I added. I also removed the last two double quotes.
With the previous two fixes for intPageNumber and this one, it works with SQL Server.<
ruirib
07 March 2006, 20:18
Ok, here is the whole code:
Code:
if mypage=-1 then strSql="SELECT REPLY_ID FROM "&strActivePrefix&"REPLY WHERE TOPIC_ID="&Topic_ID if AdminAllowed=0 then strSql=strSql&" AND (R_STATUS<" if Moderation="Y" then strSql=strSql&"2" else strSql=strSql&"3" strSql=strSql&" OR R_AUTHOR="&MemberID&")" end if strSql=strSql&" ORDER BY R_DATE ASC" set rsReplies=server.createobject("ADODB.Recordset") rsReplies.open strSql,my_Conn,adOpenStatic,adLockReadOnly,adCmdText if not rsReplies.eof then arrReplyData=rsReplies.getrows(adGetRowsRest) iReplyCount=ubound(arrReplyData,2) if len(request.querystring("REPLY_ID"))>0 then LastPostReplyID=clng(request.querystring("REPLY_ID")) for iReply=0 to iReplyCount intReplyID=arrReplyData(0,iReply) if LastPostReplyID=intReplyID then intPageNumber=((iReply+1)\strPageSize) if intPageNumber>clng(intPageNumber) then intPageNumber=clng(intPageNumber)+1 strwhichpage="whichpage="&intPageNumber&"&" exit for end if next else LastPostReplyID=arrReplyData(0,iReplyCount) intPageNumber=((iReplyCount+1)\strPageSize) if intPageNumber>clng(intPageNumber) then intPageNumber=clng(intPageNumber)+1 strwhichpage="whichpage="&intPageNumber&"&" end if else strWhichpage="" end if rsReplies.close set rsReplies=nothing my_Conn.close set my_Conn=nothing response.redirect("topic.asp?"&ArchiveLink&strwhichpage&"TOPIC_ID="&Topic_ID&SearchLink"&#"&LastPostReplyID) response.end end if
This code replaces lines#202-271 in an unchanged Snitz 3.4.05 topic.asp.<
Shaggy
08 March 2006, 06:28
Gah! That bloody &! Gets me every time!
Good man, Rui, well spotted Gonna do a bit more work on this over lunch, see if I can't try and get it to pick up last edited post without any additional queries. Don't think it's going to be possible, but worth a look any way. <
ruirib
08 March 2006, 06:32
It's your work Shaggy. Looks good and we could use it to spare some provider related problems. Well done .<
Shaggy
09 March 2006, 06:15
It doesn't look like it's going to be possible to grab the last edited post using the existing query But I have made a couple of small changes to remove the unnecessary duplication of a couple of lines and to include a check to see if the value of the REPLY_ID variable passed through the querystring is numeric:
Code:
if mypage=-1 then strSql="SELECT REPLY_ID FROM "&strActivePrefix&"REPLY WHERE TOPIC_ID="&Topic_ID if AdminAllowed=0 then strSql=strSql&" AND (R_STATUS<" if Moderation="Y" then strSql=strSql&"2" else strSql=strSql&"3" strSql=strSql&" OR R_AUTHOR="&MemberID&")" end if strSql=strSql&" ORDER BY R_DATE ASC" set rsReplies=server.createobject("ADODB.Recordset") rsReplies.open strSql,my_Conn,adOpenStatic,adLockReadOnly,adCmdText if not rsReplies.eof then arrReplyData=rsReplies.getrows(adGetRowsRest) iReplyCount=ubound(arrReplyData,2) Reply_ID=trim(chkString(request.querystring("REPLY_ID"),"sqlstring"))
if len(Reply_ID)>0 and isnumeric(Reply_ID) then LastPostReplyID=clng(Reply_ID) for iReply=0 to iReplyCount intReplyID=arrReplyData(0,iReply) if LastPostReplyID=intReplyID then intPageNumber=((iReply+1)\strPageSize) exit for end if next else LastPostReplyID=clng(arrReplyData(0,iReplyCount))
intPageNumber=((iReplyCount+1)\strPageSize) end if if intPageNumber>clng(intPageNumber) then intPageNumber=clng(intPageNumber)+1 strwhichpage="whichpage="&intPageNumber&"&"
else strWhichpage="" end if rsReplies.close set rsReplies=nothing my_Conn.close set my_Conn=nothing response.redirect "topic.asp?"&ArchiveLink&strwhichpage&"TOPIC_ID="&Topic_ID&SearchLink&"&#"&LastPostReplyID response.end end if
<
tribaliztic
09 March 2006, 06:26
I get an error on this line of that last code: response.redirect "topic.asp?"&ArchiveLink&strwhichpage&"TOPIC_ID="&Topic_ID&SearchLink"#"&LastPostReplyID
Kompileringsfel i Microsoft VBScript fel '800a0401'
LOL!!
the word "end" in swedish is causing trouble with the badword filter =) <
Shaggy
09 March 2006, 06:45
Well, for starters, the bloody & went for a walk again, thanks to the forum filtering out &#.
Secondly, can you translate that error into English for us?
<
tribaliztic
09 March 2006, 06:52
I suppose this is the correct translation:
Microsoft VBScript compilation error '800a0401' Expected end of statement
Where should I put the & ? =) <
Shaggy
09 March 2006, 06:57
Another & went walkabout in Rui's last posting of the code which I've added back in; just copy the updated redirect line from my last posting of it and all should be well.
<
tribaliztic
09 March 2006, 07:03
ah, there you go =) No errors!
But I see no link even though the option is selected in admin options. Where should it be located on the topic.asp page?
=) <
Shaggy
09 March 2006, 07:17
It shouldn't be; if you read through this topic, you'll see that this is just a modification to the existing script that will allow you to jump to the last posted reply in a topic with th need to pass the REPLY_ID through the querystring.
<
tribaliztic
09 March 2006, 07:21
Ah, that's right.. I saw that yesterday! My day haven't been that good to me so far =)
But isn't there a button also?
<
Shaggy
09 March 2006, 07:22
No - what button?
<
tribaliztic
09 March 2006, 08:08
A button where you can jump to the last post after opening the thread in topic.asp =) In admin options, under Feature Configuration I have a on/off-switch for "Show Jump To Last Post Link"...
<
Shaggy
09 March 2006, 08:15
There is no such button on topic.asp, unless you have it modded in, and this modification does not add one.
<
tribaliztic
09 March 2006, 08:27
hehe, I'm using SHN version. Maybe it's from there. I thought it was basecode.
Now when that is cleared you can take a look at my latest thread ;) <
Shaggy
13 September 2006, 12:18
Here's the final version of this code that was included in Snitz v3.4.06, released today:
Code:
if mypage=-1 then strSql="SELECT REPLY_ID FROM "&strActivePrefix&"REPLY WHERE TOPIC_ID="&Topic_ID if AdminAllowed=0 then strSql=strSql&" AND (R_STATUS<" if Moderation="Y" then strSql=strSql&"2" else strSql=strSql&"3" strSql=strSql&" OR R_AUTHOR="&MemberID&")" end if strSql=strSql&" ORDER BY R_DATE ASC" set rsReplies=server.createobject("ADODB.Recordset") if strDBType="mysql" then rsReplies.open strSql,my_Conn,adOpenForwardOnly,adLockReadOnly,adCmdText else rsReplies.open strSql,my_Conn,adOpenStatic,adLockReadOnly,adCmdText
if not rsReplies.eof then arrReplyData=rsReplies.getrows(adGetRowsRest) iReplyCount=ubound(arrReplyData,2) Reply_ID=trim(chkString(request.querystring("REPLY_ID"),"sqlstring")) if len(Reply_ID)>0 and isnumeric(Reply_ID) then LastPostReplyID=clng(Reply_ID) for iReply=0 to iReplyCount intReplyID=arrReplyData(0,iReply) if LastPostReplyID=intReplyID then intPageNumber=((iReply+1)/strPageSize) exit for end if next else LastPostReplyID=clng(arrReplyData(0,iReplyCount)) intPageNumber=((iReplyCount+1)/strPageSize) end if if intPageNumber>clng(intPageNumber) then intPageNumber=clng(intPageNumber)+1 strwhichpage="whichpage="&intPageNumber&"&" else strWhichpage="" end if rsReplies.close set rsReplies=nothing my_Conn.close set my_Conn=nothing response.redirect "topic.asp?"&ArchiveLink&strwhichpage&"TOPIC_ID="&Topic_ID&SearchLink&"&#"&LastPostReplyID response.end end if
<
Astralis
24 April 2008, 05:33
Shaggy,
I never did figure out what that green line is for, whether that is the only line that needs changed or something else.
When I looked around line 202 of topic.asp, I found the following code. Are you saying I should replace it entirely with everything you have?
Code:
if mypage = -1 and Request.QueryString("REPLY_ID") <> "" then strSql1 = "SELECT REPLY_ID " strSql2 = "FROM " & strActivePrefix & "REPLY " strSql3 = "WHERE TOPIC_ID = " & Topic_ID & " " ' 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 strSql4 = "ORDER BY R_DATE ASC "
if strDBType = "mysql" then set rsReplies = Server.CreateObject("ADODB.Recordset")
if iReplyCount <> "" then 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 end if strwhichpage = "whichpage=" & intPageNumber & "&" exit for end if next else strwhichpage = "" end if
rsReplies.Close set rsReplies = nothing else set rsReplies = Server.CreateObject("ADODB.Recordset") rsReplies.cachesize = strPageSize rsReplies.pagesize = strPageSize
if not (rsReplies.EOF or rsReplies.BOF) then if rsReplies.absolutepage > 1 then strwhichpage = "whichpage=" & rsReplies.absolutepage & "&" else strwhichpage = "" end if
rsReplies.Close set rsReplies = nothing end if
Response.Redirect("topic.asp?" & strwhichpage & "TOPIC_ID=" & Topic_ID & "#" & LastPostReplyID & "") Response.End end if
<
Shaggy
24 April 2008, 05:47
Me either, but it was a while ago now I think Davio added that line in when adding this to the base code. But, yeah, just replace that chunk of code with mine, taking care to back up topic.asp first, just in case.
<
Astralis
24 April 2008, 05:53
Excellent! It's working great! Thank you for helping me.
I figured that green line was probably a leftover from some other discussion.<