Monday, December 17, 2007

Discussion Board - How to show the details of the discussion?

Discussion Board - How to show the details of the discussion?

When we get the ID, How can we get the information in database?

Step 1 – We need to use Request.QueryString function to get the ID that the user selected:

intID=request.querystring("id")

Step 2 – Use the ID to generate a SQL command to get the record:

strSQL= "SELECT * FROM Discuss WHERE ID=" & intID


Step 3 – use the SQL to open a RecordSet:

<%

intID=request.querystring("id")

Set conn = Server.CreateObject("Adodb.Connection")

conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set rs = Server.CreateObject("Adodb.Recordset")

strSQL= "SELECT * FROM Discuss WHERE ID=" & intID

rs.open strSQL,conn,1,3

%>



Step 4 – Now you can get the data:

<%

intID=request.querystring("id")

Set conn = Server.CreateObject("Adodb.Connection")

conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set rs = Server.CreateObject("Adodb.Recordset")

strSQL= "SELECT * FROM Discuss WHERE ID=" & intID

rs.open strSQL,conn,1,3

If NOt rs.EOF then

strUser = rs.fields("User")

strTitle = rs.fields("Title")

strContent = rs.fields("Content")

strPostDate = rs.fields("PostDate")

end if

%>



Step 5– Display the Data:

<%

intID=request.querystring("id")

Set conn = Server.CreateObject("Adodb.Connection")

conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set rs = Server.CreateObject("Adodb.Recordset")

strSQL= "SELECT * FROM Discuss WHERE ID=" & intID

rs.open strSQL,conn,1,3

If NOt rs.EOF then

strUser = rs.fields("User")

strTitle = rs.fields("Title")

strContent = rs.fields("Content")

strPostDate = rs.fields("PostDate")

end if

%>

User <%=strUser%>
Post Date <%=strPostDate%>
Title <%=strTitle%>
Message <%=strContent%>

No comments: