Show how many messages since yours IN PAGE TITLE - Posted (5742 Views)
Junior Member
balexandre
Posts: 418
418
I just made this for my self as an add-on of what I did in the Forum main page (show the last 10 messages posted).
the objective was something like "GMAIL - Inbox (3)" and this is the code I uses in my page.
you can have the same in 2 steps please note that this is only to change the title of the page, the Top 10 messages that you can see in the images below ARE NOT included in this tutorial, another thing is, this only works with Access DB and MySQL above version 4.x.
  • ADD THIS IN inc_header.asp BEFORE the 2nd response.write function that had the tag:
    Code:
    <title>
    (so, search for
    Code:
    <title>
    , the 2nd one STOP and scroll up until you get the response.write, above that line, paste the include)

    paste this:

    Code:
    %><!--#INCLUDE FILE="inc_showMsgNrOnTitle.asp"><%
  • in a new file called
    Code:
    inc_showMsgNrOnTitle.asp
    paste this:

    Code:
    <%
    ' ********************************************************************************************
    ' SHOW NUMBER OF NEW MESSAGES IN TITLE IF LOGGED IN (MORE THAN 20, WILL OUTPUT +20)
    ' Built in: 26th May 2007 by Bruno Alexandre <bruno.in.dk@gmail.com>
    ' version: 0.0.2 | (29th May 2007) | updated with TopSQL() so it runs in mySQL as well (>4.x)
    ' version: 0.0.1 | (26th May 2007) | Mod Start
    ' ********************************************************************************************
    strNewMessages = ""
    intNewMessages = 0
    ' We only see the messages if the user is Logged In
    if strDBNTUserName <> "" then
    ' Get the last 20 messages order by Date
    sqlstr = "SELECT M_NAME FROM ( " & _
    "SELECT " & strTablePrefix & "TOPICS.CAT_ID, " & strTablePrefix & "TOPICS.FORUM_ID, " & strTablePrefix & "TOPICS.TOPIC_ID, " & strTablePrefix & "TOPICS.T_SUBJECT, '' AS MSG_ID, " & strTablePrefix & "TOPICS.T_MESSAGE AS MSG, " & strTablePrefix & "TOPICS.T_DATE AS MSG_DATE, " & strTablePrefix & "MEMBERS.MEMBER_ID, " & strTablePrefix & "MEMBERS.M_NAME " & _
    "FROM " & strTablePrefix & "MEMBERS INNER JOIN " & strTablePrefix & "TOPICS ON " & strTablePrefix & "MEMBERS.MEMBER_ID = " & strTablePrefix & "TOPICS.T_AUTHOR " & _
    "UNION ALL " & _
    "SELECT " & strTablePrefix & "TOPICS.CAT_ID, " & strTablePrefix & "TOPICS.FORUM_ID, " & strTablePrefix & "TOPICS.TOPIC_ID, " & strTablePrefix & "TOPICS.T_SUBJECT, " & strTablePrefix & "REPLY.REPLY_ID AS MSG_ID, " & strTablePrefix & "REPLY.R_MESSAGE as MSG, " & strTablePrefix & "REPLY.R_DATE as MSG_DATE, " & strTablePrefix & "MEMBERS.MEMBER_ID, " & strTablePrefix & "MEMBERS.M_NAME " & _
    "FROM (" & strTablePrefix & "TOPICS INNER JOIN " & strTablePrefix & "REPLY ON " & strTablePrefix & "TOPICS.TOPIC_ID = " & strTablePrefix & "REPLY.TOPIC_ID) INNER JOIN " & strTablePrefix & "MEMBERS ON " & strTablePrefix & "REPLY.R_AUTHOR = " & strTablePrefix & "MEMBERS.MEMBER_ID " & _
    ") a " & _
    "ORDER BY MSG_DATE DESC;"

    Set objRec = Server.CreateObject ("ADODB.Recordset")
    objRec.Open TopSQL(sqlstr, 20), My_Conn
    objRec.moveFirst()
    do until objRec.EOF
    if objRec.fields("M_NAME") = strDBNTUserName then
    ' Found a message from the CurrentUser, so Get out! exit do
    else
    ' The message is not from the Current User, so let's Add it to the variable
    intNewMessages = intNewMessages + 1
    end if
    objRec.moveNext()
    loop

    if intNewMessages > 0 then
    ' if the are new messages, let's surround it with curve brackets
    if objRec.EOF then
    ' there are more than 20, so, instead of looping all we show +20
    strNewMessages = "(+" & intNewMessages & ")"
    else
    strNewMessages = "(" & intNewMessages & ")"
    end if
    strNewMessages = "(" & intNewMessages & ")"
    strScriptName = strScriptName & strNewMessages
    end if

    objRec.close
    set objRec = Nothing
    end if
    %>
Hope you find this useful

my Forum: www.ga-paneuropean.com





<
 Sort direction, for dates DESC means newest first  
 Page size 
Posted
Forum Moderator
AnonJr
Posts: 5768
5768
Is it something you have to be logged in to see?<
Posted
Junior Member
balexandre
Posts: 418
418
only logged in you will be able to see that, cause... How can the MOD know who you are to tell you how many new messages are since your last one?
wink<
Posted
Forum Moderator
AnonJr
Posts: 5768
5768
You could do like active.asp does - if you're not logged in it shows all the active topics for the last 30 days. Likewise, if not logged in you could have the number of topics for the last 30 days. Or you could just provide a generic login so we can see it in action. wink
Also, these forums (as in here, not in the actual base code) have a neat little undocumented feature - [scrollcode] tags. It was added so you could post huge chunks of code like that without stretching the posts. Just a friendly tip. sleepy<
Posted
Junior Member
balexandre
Posts: 418
418
didn't know about scrollcode smile done !

humm... It's a nice ideia, but I can do that for yourself and show the code, I don't thing I'll used it cause... if you're not login, just click the Active posts link wink
the Objective is 2 be logged in and minimize the window or put the window in a new tab, and soon someone put's a message you can see it right away wink
but if you want I can add that feature! to many years under ASP / T-SQL... that's simple to implement.
By the way,
do you think I should put here the code for the Top 10 Messages MOD that I created in the forum?<
Posted
Forum Moderator
AnonJr
Posts: 5768
5768
Originally posted by balexandre
By the way,
do you think I should put here the code for the Top 10 Messages MOD that I created in the forum?
Sure. We try to encourage everybody post back fun code like that - it helps the community grow. bigsmile<
Posted
Junior Member
balexandre
Posts: 418
418
just added some pictures so everyone knows what's the propose of this code smile<
Posted
Average Member
kolucoms6
Posts: 845
845

Is it ready to download as a single file ?<
Posted
Junior Member
balexandre
Posts: 418
418
Now you lost me ...
single file?
all you need to do is copy that code in the scrolling window into a new file and rename it, saving into your forum root directory where all the forum files are, then search inside inc_header.asp for the second <title> and include that line above the response.write function for that 2nd <title><
Posted
Snitz Forums Admin
ruirib
Posts: 26364
26364
You should make it clear that this is supported only in SGBDs that support UNION queries, which excludes MySQL versions previous to 4.x. Also, the images posted are a bit misleading, since the code will only change the title of the page in a normal base Snitz version.
As a comment not meant to be seen in a negative light, the current code can be quite inefficient, since it needs to navigate through all the records to find out the total number of new posts. You could use the current UNION query as subquery of a new query just to count the number records returned by the UNION query and then just retrieve the returned value.
As an alternative, two SELECT COUNT(*) queries, one for the topics, another for replies, would do it too. This latter option would even be available to MySQL 3.x databases.<
Posted
Junior Member
balexandre
Posts: 418
418
never used mySQL, and I do not know what are the differences on t-sql, my world is only MS SQL smile
please fell free to update a T-SQL Code smile
about looping, yes, but my Access Database knowledge is limited and only led me to that, in MS SQL, I would use an SP, retrieve both count and sum ... easy, but not supported by Access.
But: I changed the code, so now I request the TOP 20 and if more than 20 I simple say (+20) instead of looping all the messages in the Database... this was a really issue if the user is a new member and not yet any posts wink <Obrigado!>

As suggested, I will edit my post and add that message about UNION function smile
about the images... humm, I even added "Objective", the Top 10 messages is other MOD that I created, and like AnonJR said, I will post it as well, but right now it's codded for my Forum, and no comments or other options as 1 vertical table with all 10 messages.
to place the MOD I should, at least, place some options, like Vertical / Horizontal and how many Rows / Columns<
You Must enter a message