Author |
Topic |
|
Fastalanasa
Starting Member
USA
7 Posts |
Posted - 20 March 2002 : 04:20:07
|
I'm trying to make a simple mod to let my users see how many active topics there are in the front page of my web site. I'm almost there, but I just need a little tweak to make it work right. The code I have is below:
strCookieURL = Left(Request.ServerVariables("Path_Info"), InstrRev(Request.ServerVariables("Path_Info"), "/"))
strSQL = "SELECT COUNT(FORUM_TOPICS.T_LAST_POST) AS NUM_ACTIVE FROM FORUM_TOPICS WHERE FORUM_TOPICS.T_STATUS <= 1 " strSQL = strSQL & "AND (((FORUM_TOPICS.T_LAST_POST)>'"& Session(strCookieURL & "last_here_date") & "'))"
Set Conn = SERVER.CREATEOBJECT("ADODB.Connection") Set rs = SERVER.CREATEOBJECT("ADODB.RecordSet") Conn.OPEN "Driver={SQL Server};Server=****;Database=****;Uid=****;Pwd=****;"
rs.open strSQL, Conn
if not rs.EOF then ActiveTopicCount = rs("NUM_ACTIVE") strNewTopicMsg = "There are " & CStr(ActiveTopicCount) & " new topics in the forums." else ActiveTopicCount = 0 strNewTopicMsg = "" end if
Set Conn = Nothing Set rs = Nothing
My problem is here: Session(strCookieURL & "last_here_date") All I need is to be able to get the date in the above code. Can anybody help or give me some pointers?
- Fastalanasa
|
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 20 March 2002 : 06:33:56
|
StrCookieURL is probably defaulting to "" so try either adding an include for config.asp at the start of your page (might need inc_functions also) or just setting strCookieURL = "/forum/" somewhere in that page.
www.daoc-halo.com |
|
|
Fastalanasa
Starting Member
USA
7 Posts |
Posted - 20 March 2002 : 10:34:33
|
Thanks!!!
Just added "Forums/" at the end of the strCookieURL declaration. This works without any include and will work on any page outside of the Forums.
The whole script is below for those who want it:
Dim strUser Dim strMessage Dim strNewTopicMsg Dim strSQL Dim strCookieURL Dim ActiveTopicCount Dim strVerb Dim strPlural
strCookieURL = Left(Request.ServerVariables("Path_Info"), InstrRev(Request.ServerVariables("Path_Info"), "/")) & "Forums/"
strSQL = "SELECT COUNT(FORUM_TOPICS.T_LAST_POST) AS NUM_ACTIVE FROM FORUM_TOPICS WHERE FORUM_TOPICS.T_STATUS <= 1 " strSQL = strSQL & "AND (((FORUM_TOPICS.T_LAST_POST)>'"& Session(strCookieURL & "last_here_date") & "'))"
Set Conn = SERVER.CREATEOBJECT("ADODB.Connection") Set rs = SERVER.CREATEOBJECT("ADODB.RecordSet") Conn.OPEN "Driver={SQL Server};Server=*****;Database=****;Uid=*******;Pwd=***;"
rs.open strSQL, Conn
if not rs.EOF then ActiveTopicCount = rs("NUM_ACTIVE") If ActiveTopicCount = 1 Then strVerb = " is " strPlural = "topic" Else strVerb = " are " strPlural = "topics" End If strNewTopicMsg = "There" & strVerb & CStr(ActiveTopicCount) & " new " & strPlural & " in the forums." else ActiveTopicCount = 0 strNewTopicMsg = "" end if
Set Conn = Nothing Set rs = Nothing
strUser = Request.Cookies("Snitz00User")("Name") If strUser = "" Then strUser = "Guest" strMessage = "Hi Guest! Welcome to WheelMUD." Else strMessage = "Welcome back, " & strUser & "! " & strNewTopicMsg End If
|
|
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 20 March 2002 : 18:22:21
|
[quote]Thanks!!![quote]
Your welcome, glad you got it working. That will be a handy little script.
www.daoc-halo.com |
|
|
kjartis
New Member
Norway
94 Posts |
Posted - 21 March 2002 : 00:15:57
|
Cool, could someone make a code like this for Access?
|
|
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 21 March 2002 : 02:43:54
|
If you just change the connection string to your Access one it should work I think ok in access as well.
This is the line you need to alter
Conn.OPEN "Driver={SQL Server};Server=*****;Database=****;Uid=*******;Pwd=***;"
If your unsure what your connection string is, take a look in your config.asp file and cut and paste the information from the strConnString variable.
www.daoc-halo.com |
|
|
kjartis
New Member
Norway
94 Posts |
Posted - 21 March 2002 : 07:34:14
|
Thanks, I'll try it!
|
|
|
Fastalanasa
Starting Member
USA
7 Posts |
Posted - 21 March 2002 : 14:28:25
|
There were some problems with the code above. I had my users test it and now it works correctly. I copied and pasted some functions from inc_functions.asp and config.asp. I had to modify the ReadLastHereDate function. That's why instead of doing an #include, I just copied an pasted the code in this script. Here's the full code:
<%
function ChkDateFormat(strDateTime) ChkDateFormat = isdate("" & Mid(strDateTime, 5,2) & "/" & Mid(strDateTime, 7,2) & "/" & Mid(strDateTime, 1,4) & " " & Mid(strDateTime, 9,2) & ":" & Mid(strDateTime, 11,2) & ":" & Mid(strDateTime, 13,2) & "") end function
function StrToDate(strDateTime) if ChkDateFormat(strDateTime) then StrToDate = cdate("" & Mid(strDateTime, 5,2) & "/" & Mid(strDateTime, 7,2) & "/" & Mid(strDateTime, 1,4) & " " & Mid(strDateTime, 9,2) & ":" & Mid(strDateTime, 11,2) & ":" & Mid(strDateTime, 13,2) & "") else StrToDate = "" & strForumTimeAdjust end if end function
function DateToStr(dtDateTime) DateToStr = year(dtDateTime) & doublenum(Month(dtdateTime)) & doublenum(Day(dtdateTime)) & doublenum(Hour(dtdateTime)) & doublenum(Minute(dtdateTime)) & doublenum(Second(dtdateTime)) & "" end function
function doublenum(fNum) if fNum > 9 then doublenum = fNum else doublenum = "0" & fNum end if end function
function ReadLastHereDate(UserName)
dim TempLastHereDate dim rs_date
strTimeAdjust = Application("/FORUMS/STRTIMEADJUST") strForumTimeAdjust = DateAdd("h", strTimeAdjust , Now())
'## Forum_SQL strSql = "SELECT FORUM_MEMBERS.M_LASTHEREDATE " strSql = strSql & " FROM FORUM_MEMBERS " strSql = strSql & " WHERE FORUM_MEMBERS.M_NAME = '" & UserName & "' "
Set Conn = SERVER.CREATEOBJECT("ADODB.Connection") Conn.OPEN "Driver={SQL Server};Server=*****;Database=*****;Uid=***;Pwd=***;" set rs_date = Conn.Execute (strSql)
if (rs_date.BOF and rs_date.EOF) then TempLastHereDate = DateAdd("d",-10,strForumTimeAdjust) else TempLastHereDate = StrToDate(rs_date("M_LASTHEREDATE")) if TempLastHereDate = "" or IsNull(TempLastHereDate) then TempLastHereDate = DateAdd("d",-10,strForumTimeAdjust) end if end if
rs_date.close set rs_date = nothing
ReadLastHereDate = DateToStr(TempLastHereDate)
end function %>
<% Dim strUser Dim strMessage Dim strNewTopicMsg Dim strSQL Dim strCookieURL Dim ActiveTopicCount Dim strVerb Dim strPlural
strCookieURL = Left(Request.ServerVariables("Path_Info"), InstrRev(Request.ServerVariables("Path_Info"), "/")) & "Forums/" Session(strCookieURL & "last_here_date") = ReadLastHereDate(Request.Cookies("Snitz00User")("Name"))
strSQL = "SELECT COUNT(FORUM_TOPICS.T_LAST_POST) AS NUM_ACTIVE FROM FORUM_TOPICS WHERE FORUM_TOPICS.T_STATUS <= 1 " strSQL = strSQL & "AND (((FORUM_TOPICS.T_LAST_POST)>'"& Session(strCookieURL & "last_here_date") & "'))"
Set Conn = SERVER.CREATEOBJECT("ADODB.Connection") Set rs = SERVER.CREATEOBJECT("ADODB.RecordSet") Conn.OPEN "Driver={SQL Server};Server=*****;Database=*****;Uid=***;Pwd=***;"
rs.open strSQL, Conn
if not rs.EOF then ActiveTopicCount = rs("NUM_ACTIVE") Select Case ActiveTopicCount Case 0 ActiveTopicCount = 0 strNewTopicMsg = "There are no new topics in the forums." Case 1 strVerb = " is " strPlural = "topic" strNewTopicMsg = "There" & strVerb & CStr(ActiveTopicCount) & " new " & strPlural & " in the forums." Case Else strVerb = " are " strPlural = "topics" strNewTopicMsg = "There" & strVerb & CStr(ActiveTopicCount) & " new " & strPlural & " in the forums." End Select
else ActiveTopicCount = 0 strNewTopicMsg = "" end if
Set Conn = Nothing Set rs = Nothing
'Response.Write strSQL
strUser = Request.Cookies("Snitz00User")("Name") If strUser = "" Then strUser = "Guest" strMessage = "Hi Guest! Welcome to WheelMUD." Else strMessage = "Welcome back, " & strUser & "! " & strNewTopicMsg End If %>
Edited by - Fastalanasa on 21 March 2002 14:31:14 |
|
|
kjartis
New Member
Norway
94 Posts |
Posted - 21 March 2002 : 18:58:12
|
I tryed bouth your codes with a Access database. I set the connstring as told above without getting it to work!
What have I done wrong?
My code: <% function ChkDateFormat(strDateTime) ChkDateFormat = isdate("" & Mid(strDateTime, 5,2) & "/" & Mid(strDateTime, 7,2) & "/" & Mid(strDateTime, 1,4) & " " & Mid(strDateTime, 9,2) & ":" & Mid(strDateTime, 11,2) & ":" & Mid(strDateTime, 13,2) & "") end function function StrToDate(strDateTime) if ChkDateFormat(strDateTime) then StrToDate = cdate("" & Mid(strDateTime, 5,2) & "/" & Mid(strDateTime, 7,2) & "/" & Mid(strDateTime, 1,4) & " " & Mid(strDateTime, 9,2) & ":" & Mid(strDateTime, 11,2) & ":" & Mid(strDateTime, 13,2) & "") else StrToDate = "" & strForumTimeAdjust end if end function function DateToStr(dtDateTime) DateToStr = year(dtDateTime) & doublenum(Month(dtdateTime)) & doublenum(Day(dtdateTime)) & doublenum(Hour(dtdateTime)) & doublenum(Minute(dtdateTime)) & doublenum(Second(dtdateTime)) & "" end function function doublenum(fNum) if fNum > 9 then doublenum = fNum else doublenum = "0" & fNum end if end function function ReadLastHereDate(UserName) dim TempLastHereDate dim rs_date strTimeAdjust = Application("/FORUMS/STRTIMEADJUST") strForumTimeAdjust = DateAdd("h", strTimeAdjust , Now()) '## Forum_SQL strSql = "SELECT FORUM_MEMBERS.M_LASTHEREDATE " strSql = strSql & " FROM FORUM_MEMBERS " strSql = strSql & " WHERE FORUM_MEMBERS.M_NAME = '" & UserName & "' " Set Conn = SERVER.CREATEOBJECT("ADODB.Connection") strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\***\***\*****\******.mdb" set rs_date = Conn.Execute (strSql) if (rs_date.BOF and rs_date.EOF) then TempLastHereDate = DateAdd("d",-10,strForumTimeAdjust) else TempLastHereDate = StrToDate(rs_date("M_LASTHEREDATE")) if TempLastHereDate = "" or IsNull(TempLastHereDate) then TempLastHereDate = DateAdd("d",-10,strForumTimeAdjust) end if end if rs_date.close set rs_date = nothing ReadLastHereDate = DateToStr(TempLastHereDate) end function %> <% Dim strUser Dim strMessage Dim strNewTopicMsg Dim strSQL Dim strCookieURL Dim ActiveTopicCount Dim strVerb Dim strPlural strCookieURL = Left(Request.ServerVariables("Path_Info"), InstrRev(Request.ServerVariables("Path_Info"), "/")) & "Forums/" Session(strCookieURL & "last_here_date") = ReadLastHereDate(Request.Cookies("Snitz00User")("Name")) strSQL = "SELECT COUNT(FORUM_TOPICS.T_LAST_POST) AS NUM_ACTIVE FROM FORUM_TOPICS WHERE FORUM_TOPICS.T_STATUS <= 1 " strSQL = strSQL & "AND (((FORUM_TOPICS.T_LAST_POST)>'"& Session(strCookieURL & "last_here_date") & "'))" Set Conn = SERVER.CREATEOBJECT("ADODB.Connection") Set rs = SERVER.CREATEOBJECT("ADODB.RecordSet") strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\***\***\*****\******.mdb" rs.open strSQL, Conn if not rs.EOF then ActiveTopicCount = rs("NUM_ACTIVE") Select Case ActiveTopicCount Case 0 ActiveTopicCount = 0 strNewTopicMsg = "There are no new topics in the forums." Case 1 strVerb = " is " strPlural = "topic" strNewTopicMsg = "There" & strVerb & CStr(ActiveTopicCount) & " new " & strPlural & " in the forums." Case Else strVerb = " are " strPlural = "topics" strNewTopicMsg = "There" & strVerb & CStr(ActiveTopicCount) & " new " & strPlural & " in the forums." End Select else ActiveTopicCount = 0 strNewTopicMsg = "" end if Set Conn = Nothing Set rs = Nothing 'Response.Write strSQL strUser = Request.Cookies("Snitz00User")("Name") If strUser = "" Then strUser = "Guest" strMessage = "Hi Guest! Welcome to WheelMUD." Else strMessage = "Welcome back, " & strUser & "! " & strNewTopicMsg End If %>
|
|
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 21 March 2002 : 19:03:22
|
It would help if you also told us what error you were getting
www.daoc-halo.com |
|
|
kjartis
New Member
Norway
94 Posts |
Posted - 21 March 2002 : 19:39:55
|
Jupp!
Code #1 by Fastalanasa: http://kjartis.com/test/forum2.asp Error: Microsoft OLE DB Provider for ODBC Drivers error '80004005' [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified /test/forum2.asp, line 23 Line 23 is: CONN.OPEN ConnString
Code #2 by Fastalanasa: http://kjartis.com/test/forum3.asp Error: HTTP 500
I have used the same connstring in bouth of the codes!
Thanks! :)
Edited by - Kjartis on 21 March 2002 19:49:38 |
|
|
Fastalanasa
Starting Member
USA
7 Posts |
Posted - 21 March 2002 : 23:22:08
|
Let me make an official MOD then. I'll make it so that it will use the connection string that your forum is already using. I'll make it as simple as possible, so that people don't have to really change code, just cut and paste. It's kind of late tonight, so I'll have a zip and readme file tomorrow morning.
- Fastalanasa
PS. To see it working go to http://www.wheelmud.org . If you register in the forum there, you will see the script in action when you go back to the website's home page. Cheers!
|
|
|
kjartis
New Member
Norway
94 Posts |
Posted - 22 March 2002 : 00:42:41
|
That sounds great! Thanks! :)
|
|
|
Fastalanasa
Starting Member
USA
7 Posts |
|
kjartis
New Member
Norway
94 Posts |
Posted - 22 March 2002 : 15:54:12
|
Great MOD! Works like a charm! :) I use a lot of other scripts on my frontpage that comes in conflicts with it! But it will most likely be usefull for a lot of other users!
Great work! Thanks again!
|
|
|
|
Topic |
|