| Author |
Topic Search Topic Options
|
Mattias Nordin
Groupie
Joined: 30 March 2005
Status: Offline
Points: 60
|
Post Options
Thanks(0)
Quote Reply
Topic: Get Top 10 posts and topics for MySql Posted: 28 July 2008 at 3:19pm |
I created the following script to show the top7 posts (including topic) for my web wiz forum version 8. I had it running on a access database. It worked fine.
Now i have installed version 9 on a new server and that server has mySql installed. Anyone knows how to change the connection string to work with mySql?
Is all the table names still valid or do i need to change the sql syntax? I have limited expreience in MySql
<%'===== Access odbc ===== Set objCon = Server.CreateObject( "Adodb.Connection" ) objCon.Provider = "Microsoft.Jet.OLEDB.4.0" 'MdbFilePath = Server.MapPath( "/web2005/fotoalbum/fotoalbum.mdb") MdbFilePath = "D:\secureWebAccess\webwizForumet.mdb" objCon.ConnectionString = "Data Source='" & MdbFilePath & "'" objCon.open %>
<% strDBTrue = "True" strDBFalse = "False" strSQL = " SELECT TOP 7 " strSQL = strSQL & "tblForum.Forum_name, tblTopic.Topic_ID, tblTopic.Subject, tblThread.Thread_ID, tblThread.Message_date, tblAuthor.Author_ID, " &_ " tblAuthor.Username, tblThread.Message, tblTopic.No_of_views " & _ " FROM tblForum, tblTopic, tblAuthor, tblThread, tblPermissions " & _ " WHERE tblForum.Forum_ID = tblTopic.Forum_ID " & _ " AND tblTopic.Topic_ID = tblThread.Topic_ID " & _ " AND tblAuthor.Author_ID = tblThread.Author_ID " & _ " AND tblForum.Forum_ID = tblPermissions.Forum_ID " & _ " AND (tblPermissions.Group_ID = 2 AND tblPermissions.View_Forum = " & strDBTrue & ") " strSQL = strSQL & " AND (tblForum.Password = '' OR tblForum.Password Is Null) AND (tblTopic.Hide = " & strDBFalse & " AND tblThread.Hide = " & strDBFalse & ") ORDER BY tblThread.Message_date DESC " 'response.write strSQL set rs = objCon.execute(strSQL) %>
<table border=0 cellpadding=6> <% while not rs.eof varLastAuthor = rs("Username") varSubject = rs("Subject") varLastEntryDate = rs("Message_date") varViewsNum = rs("No_of_views") varId = rs("Topic_ID") varForumName = rs("Forum_name")%> <tr><td width=34 align="center"> <a href="/web07/tab5/forum_posts.asp?TID=<%=varId%>&PN=1"><img border=0 src="/web07/tab1/top5fromForum/ico_32_senast_forum.gif"></a><br> <a href="/web07/tab5/forum_posts.asp?TID=<%=varId%>&PN=1">Läs</a> </td><td> <div class=text> <font face=tahoma size=2><b><%=varSubject%></b></font><div style="margin-bottom:3px;"></div> <font face=tahoma size=1 color=gray>Från forumet "<%=varForumName%>"</font><br> <font size=1 face=tahoma> <%=funForumLogicDate(varLastEntryDate)%> av <%=varLastAuthor %>. Läst <%=varViewsNum%> ggr. </font> </div> </td></tr> <% rs.movenext wend %> </table>
<% 'Returnerar när en post senast var uppdaterad. Ex Idag 15:45 eller Torsdag 10:00 function funForumLogicDate(varInputDate) varDateDiff = dateDiff("d", varInputDate, now) varHour = hour(varInputDate) varHour = "00" &varHour varHour = right(varHour,2) varMinute = minute(varInputDate) varMinute = "00" &varMinute varMinute = right(varMinute,2) if varDateDiff = 0 then varDateText = "Today " &varHour &":" &varMinute varDateText = "<font color=red>" &varDateText &"</font>" elseif varDateDiff < 7 then varDateText = WeekdayName(WeekDay(varInputDate)) &" " &varHour &":" &varMinute else varDateText = left(varInputDate,10) end if funForumLogicDate = varDateText end function%>
|
|
 |
i2Paq
Groupie
Joined: 10 April 2004
Location: Netherlands
Status: Offline
Points: 181
|
Post Options
Thanks(0)
Quote Reply
Posted: 28 July 2008 at 8:57pm |
Did you test that code with a version 9 using acces?
To my knowledge the code should be the same accessing SQL or Access, otherwise there should be separate WebWiz files for use with Access, SQL or MySQL.
|
 |
Mattias Nordin
Groupie
Joined: 30 March 2005
Status: Offline
Points: 60
|
Post Options
Thanks(0)
Quote Reply
Posted: 30 July 2008 at 8:48pm |
When i run the code above i get;
Microsoft JET Database Engine error '80004005'
Disk or network error. /web08/default.asp, line 89 |
Line 89 = objCon.open
In this case it's obvious that it's wrong since i try to open a file that does not exist. If i try to move my old access database to the new server it works fine.
To start with, i need a new connection string to MySQL. Can anyone help me with this?
|
 |
Mattias Nordin
Groupie
Joined: 30 March 2005
Status: Offline
Points: 60
|
Post Options
Thanks(0)
Quote Reply
Posted: 30 July 2008 at 9:03pm |
I think i figured out how to create an ASP connection string:
<% strSQLServerName = "xxServer" 'Holds the name of the SQL Server (This is the name/location or IP address of the SQL Server) strSQLDBUserName = " xxUser" 'Holds the user name (for SQL Server Authentication) strSQLDBPassword = "xxPass" 'Holds the password (for SQL Server Authentication) strSQLDBName = "xxDatabaseName" 'Initilise the DB Connection String strCon = "DRIVER={MySQL ODBC 3.51 Driver}; Server=" & strSQLServerName & ";User ID=" & strSQLDBUserName & ";Password=" & strSQLDBPassword & ";Database=" & strSQLDBName & ";" Set objCon = Server.CreateObject( "Adodb.Connection" ) objCon.open strCon %>
|
 |
Scotty32
Moderator Group
Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
|
Post Options
Thanks(0)
Quote Reply
Posted: 30 July 2008 at 9:16pm |
|
Would it not be easier to include the 'common.asp' file?
|
|
|
 |
Mattias Nordin
Groupie
Joined: 30 March 2005
Status: Offline
Points: 60
|
Post Options
Thanks(0)
Quote Reply
Posted: 30 July 2008 at 9:57pm |
Perhaps. But i got the query string working now. I have another problem though.
I have never used mySql before and am not sure about the syntax. I used "limit 10" to get "Top 10" out of my query. But i do get a strange result compared on how it worked in access.
strDBTrue = "True" strDBFalse = "False" strSQL = " SELECT tblForum.Forum_name, tblTopic.Topic_ID, tblTopic.Subject, tblThread.Thread_ID, tblThread.Message_date, tblAuthor.Author_ID, " &_ " tblAuthor.Username, tblThread.Message, tblTopic.No_of_views " & _ " FROM tblForum, tblTopic, tblAuthor, tblThread, tblPermissions " & _ " WHERE tblForum.Forum_ID = tblTopic.Forum_ID " & _ " AND tblTopic.Topic_ID = tblThread.Topic_ID " & _ " AND tblAuthor.Author_ID = tblThread.Author_ID " & _ " AND tblForum.Forum_ID = tblPermissions.Forum_ID " & _ " AND (tblForum.Password = '' OR tblForum.Password Is Null) AND (tblTopic.Hide = " & strDBFalse & " AND tblThread.Hide = " & strDBFalse & ") " &_ " ORDER BY tblThread.Message_date DESC " &_ " LIMIT 10 " response.write strSQL
|
The result is found in the right part of this page:
Note that the first post is looped 7 times before the second post is shown. How come?
|
 |
Mattias Nordin
Groupie
Joined: 30 March 2005
Status: Offline
Points: 60
|
Post Options
Thanks(0)
Quote Reply
Posted: 30 July 2008 at 11:17pm |
I rewrote the sql code and this works fine on MySql :)
This will show a list of the 10 last topics and the name of the forum they were posted in. Also number of views will be shown.
<% strDBTrue = "True" strDBFalse = "False" strSQL = " SELECT tblTopic.subject, tblTopic.Topic_ID, tblTopic.Topic_ID, tblTopic.No_of_views, tblAuthor.Username, tblThread.Message_date, tblForum.Forum_name" &_ " FROM tblTopic " & _ " INNER JOIN tblThread ON (tblTopic.Topic_ID = tblThread.Topic_ID) " &_ " INNER JOIN tblAuthor ON (tblThread.Author_ID = tblAuthor.Author_ID) " &_ " INNER JOIN tblForum ON (tblTopic.Forum_ID = tblForum.Forum_ID) " &_ " WHERE (tblForum.Password = '' OR tblForum.Password Is Null) AND (tblTopic.Hide = " & strDBFalse & " AND tblThread.Hide = " & strDBFalse & ") " &_ " ORDER BY Message_date DESC " &_ " LIMIT 10 " 'response.write(" Query = " &strSQL) set rs = objCon.execute(strSQL) %>
<table border=0 cellpadding=6> <% while not rs.eof varLastAuthor = rs("Username") varSubject = rs("Subject") varLastEntryDate = rs("Message_date") varViewsNum = rs("No_of_views") varId = rs("Topic_ID") varForumName = rs("Forum_name")%> <tr><td width=34 align="center"> <a href="/web08/forum/forum_posts.asp?TID=<%=varId%>&PN=1"><img border=0 src="/web08/_design/forum_icon.gif"></a><br> <a href="/web08/forum/forum_posts.asp?TID=<%=varId%>&PN=1">Läs</a> </td><td> <div class=text> <font face=tahoma size=2><b><%=varSubject%></b></font><div style="margin-bottom:3px;"></div> <font face=tahoma size=1 color=gray>Från forumet "<%=varForumName%>"</font><br> <font size=1 face=tahoma> <%=funForumLogicDate(varLastEntryDate)%> (<%=varLastEntryDate%>) av <%=varLastAuthor %>. Läst <%=varViewsNum%> ggr. </font> </div> </td></tr> <% rs.movenext wend %>
|
Best regards Mattias Nordin
|
 |
i2Paq
Groupie
Joined: 10 April 2004
Location: Netherlands
Status: Offline
Points: 181
|
Post Options
Thanks(0)
Quote Reply
Posted: 31 July 2008 at 1:57pm |
That looks great!
I use the Who Visited Today mod made by Scotty32, download it here.
Would you be willing to include this on the forum index.php from that download?
I'm using the 9.50 Free (access db) version, just like you.
I'm willing to donate a small amount of $ to your work 
|
 |