Jump to content

Comments on the page


denny911

Recommended Posts

Jerome, you managed to help me 2 times so far. Please, try to help me again.My previous problem was how to display one particular article according to the ID contained in the link (news.asp ----> details.asp?ID=123)Now, with your help I am able to open an article on the details.asp page. But, beneath the article I would like to have a link named Comment. When a user clicks it, I want a window to pop-up and open a page, let's call it comment.asp.I've made that pop-up window, and also comment.asp page and even form and database for users' comments.I used this code:<%set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open(Server.Mappath("testdb.mdb"))sql="INSERT INTO comments (nick, comment)"sql=sql & " VALUES "sql=sql & "('" & Request.Form("nick") & "',"sql=sql & "'" & Request.Form("comment") & "');"on error resume nextconn.Execute sql,recaffected%>so I'm able to insert a comment in the form placed on the page, and data is sent to the database.The code below lists selected fields from a table named "comments".<%set rs = Server.CreateObject("ADODB.recordset")dataSQL = "SELECT nick, comment, time FROM comments"rs.Open dataSQL, conndo until rs.EOF for each x in rs.Fields Response.Write(x.value & "<br/>") next Response.Write("</br>") rs.MoveNextloopconn.close%>So, when opened in pop-up window, comment.asp page basically looks like this:----------------------------------------------------------------------------------------------DONALD DUCKThis is the Donald's comment about some article.13.11.2005 18:28:14ROAD RUNNERThis is Road Runner's comment.10.11.2005 12:04:19Nick: |______________________________________________Comment: |__________________________________________SUBMIT RESET-----------------------------------------------------------------------------------------------But, this code lists all comments (that is, records) from the table. I would like to have one table that will contain comments for all articles on my site. So, similar to my previous problem, if a user gets to the article from news.asp by clicking link .../details.asp?ID=123, I want the link Comment to be ..comment.asp?ID=123 and, after clicking that link, a pop-up window would be displayed opening comment.asp page that would display comments about ONLY the article ID=123.Can you tell me how to organize my comments table (or maybe it's better to make a database for comments only?) and also write me down some code to use in my comment.asp page to have it display only comments I want it to display and NOT all the records contained in a table.Thank you!Denis K., Bosnia H.P.S. If you need more details about anything, feel free to ask.

Link to comment
Share on other sites

Hi Denis,You should have a comments table with those fields : nick, comment, newsID, time"Donald", "This is a comment",123, "10/11/2005"Where newsID contains the id of the news related to one comment in particular.So, at the time a user inserts a comment, you should also insert the id of the news that he is commenting.

sql="INSERT INTO comments (nick, comment, newsID)"sql=sql & " VALUES "sql=sql & "('" & Request.Form("nick") & "',"sql=sql & "'" & Request.Form("comment") & "'," & newsID & "');"

Now when you display the comments, you can use the id of one particular news to make a selection in your comments table :

dataSQL = "SELECT nick, comment, newsID, time FROM comments WHERE newsID = ID"

What is the url of your site?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...