 |
01-09-2008, 08:29 PM
|
make a blog/forum
|
Posts: 77
|
I dont need to know how to actually code it, but just how it works.
For a blog, you make posts, and then people comment on them.
So you have a table that saves the title, body, date and other info about each post. So where how are comments added?
What about forums?
|
|
|
|
01-09-2008, 08:56 PM
|
Re: make a blog/forum
|
Posts: 3,016
Name: Forrest Croce
Location: Seattle, WA
|
For a blog, I would store the comments in one table and posts in another. I might experiment a little for performance reasons; possibly a table with nothing but the long data, ie the post or comment bodies, then a posts table with the title, date, and such, and a comment table also with the date and author, each linking to a specific ID in the 'body' table. That would just depend on how the system is used, what database platform, and how you map things to disc.
A forum has a lot of posts, and each of them belong to a thread. I would simply have a threads table with a date, ID, and other things, then a posts table, each post with a thread ID. Where the title goes depends on whether replies can have their own titles.
|
|
|
|
01-25-2008, 09:26 PM
|
Re: make a blog/forum
|
Posts: 77
|
Anything wrong with this code?:
Code:
varp=cint(Request.QueryString("p"))
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("d/b.mdb")
Conn.Open
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "SELECT id,post,name,email,body FROM comments WHERE comments.post = " & varp & ";", conn, 1, 3
Do While not rs.EOF
response.write ("<b><a href=""mailto:"& rs(email) &""">"& rs("name") &"</a></b><br>"& rs("body"))
rs.MoveNext
Loop
Its supposed to find every comment that is for a certain post then display them.But I just get:
Microsoft JET Database Engine error '80040e07'
Data type mismatch in criteria expression.
|
|
|
|
01-26-2008, 02:45 AM
|
Re: make a blog/forum
|
Posts: 11,452
Location: Blackpool. UK
|
varp is probably empty
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
|
|
|
|
01-26-2008, 12:28 PM
|
Re: make a blog/forum
|
Posts: 77
|
Quote:
Originally Posted by chrishirst
varp is probably empty
|
No, because I have it the post from another table right before that(maybe it has something to do with that?) Heres the URL:
http://skeddles.com/comments.asp?p=1
|
|
|
|
01-26-2008, 06:50 PM
|
Re: make a blog/forum
|
Posts: 11,452
Location: Blackpool. UK
|
print out the SQL command string before calling the open method.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
|
|
|
|
01-26-2008, 09:51 PM
|
Re: make a blog/forum
|
Posts: 77
|
Quote:
Originally Posted by chrishirst
print out the SQL command string before calling the open method.
|
sorry, I tried fooling around, and looking it up online, but i'm not sure what that means. Still a newb.
|
|
|
|
01-27-2008, 11:20 AM
|
Re: make a blog/forum
|
Posts: 11,452
Location: Blackpool. UK
|
response.write "SELECT id,post,name,email,body FROM comments WHERE comments.post = " & varp & ";"
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
|
|
|
|
01-27-2008, 04:48 PM
|
Re: make a blog/forum
|
Posts: 77
|
Quote:
Originally Posted by chrishirst
response.write "SELECT id,post,name,email,body FROM comments WHERE comments.post = " & varp & ";"
|
Still the same, now it just prints that on the top of the page..
heres my entire code, the first part is reading the posts database, then print the post it is supposed to, and that part works, the next part is supposed to get all the comments.
Code:
varp=cint(Request.QueryString("p"))
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("d/b.mdb")
Conn.Open
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "SELECT id,title,body,date,commnum FROM posts WHERE posts.id = " & varp & ";", Conn, 1,3
response.write ("<BR><center><table border=""0"" cellspacing=""0"" cellpadding=""0""><tr><td colspan=""2""><img border=""0"" src=""x/hr.gif""/></td></tr><tr><td colspan=""2""><center><b>"& rs("title") &"</b></center></td></tr><tr><td width=""680"" colspan=""2"">"& rs("body") &"</td></tr><tr><td colspan=""2"" align=""left"">"& rs("date") &"</td></tr><tr><td align=""center"" colspan=""2""><img border=""0"" src=""x/hr.gif""/></td></tr></table></center><BR>")
dim iii
iii = rs("commnum")
set Rs = nothing
set Conn = nothing
if iii = "0" then
response.write ("There are no comments. Be the first to make a comment:<BR>")
response.write ("<form action=""savecom.asp?f=blog""><table><tr><td valign=""top"">Name:</td><td><input type=""text"" name=""name"" size=""40""></td></tr><tr><td valign=""top"">Email:</td><td><input type=""text"" name=""email"" size=""40""></td></tr><tr><td valign=""top"">Comment:</td><td><textarea name=""body"" cols=""25"" rows=""5""></textarea></td></tr></table></form>")
else
response.write ("Comments:")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("d/b.mdb")
Conn.Open
Set Rs = Server.CreateObject("ADODB.Recordset")
Response.write "SELECT id,post,name,email,body FROM comments WHERE comments.post = " & varp & ";"
Rs.Open "SELECT id,post,name,email,body FROM comments WHERE comments.post=" & varp & ";", conn, 1, 3
response.write ("<b><a href=""mailto:"& rs(email) &""">"& rs("name") &"</a></b><br>"& rs("body"))
response.write ("<form action=""savecom.asp?f=blog""><table><tr><td valign=""top"">Name:</td><td><input type=""text"" name=""name"" size=""40""></td></tr><tr><td valign=""top"">Email:</td><td><input type=""text"" name=""email"" size=""40""></td></tr><tr><td valign=""top"">Comment:</td><td><textarea name=""body"" cols=""25"" rows=""5""></textarea></td></tr></table></form>")
end if
set Rs = nothing
set Conn = nothing
|
|
|
|
01-27-2008, 05:10 PM
|
Re: make a blog/forum
|
Posts: 11,452
Location: Blackpool. UK
|
Quote:
|
Still the same, now it just prints that on the top of the page..
|
As it would, this is debugging101.
So, now we have eliminated the possibility of "p" being empty or NULL
move on the the next possibility
what is the datatype of the column "comments.post" ?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
|
|
|
|
01-27-2008, 05:32 PM
|
Re: make a blog/forum
|
Posts: 77
|
Quote:
Originally Posted by chrishirst
As it would, this is debugging101.
So, now we have eliminated the possibility of "p" being empty or NULL
move on the the next possibility
what is the datatype of the column "comments.post" ?
|
its a text with a fieldsize of 50
|
|
|
|
01-27-2008, 06:49 PM
|
Re: make a blog/forum
|
Posts: 11,452
Location: Blackpool. UK
|
Quote:
|
its a text with a fieldsize of 50
|
and there is your bug.
varp=cint(Request.QueryString("p")) <> string
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
|
|
|
|
01-27-2008, 10:31 PM
|
Re: make a blog/forum
|
Posts: 77
|
Quote:
Originally Posted by chrishirst
and there is your bug.
varp=cint(Request.QueryString("p")) <> string
|
I pasted the portion of the code i'm having trouble with in a new document.
http://skeddles.com/coms2.asp?p=1
Code:
<%
varp=cint(Request.QueryString("p")) <> string
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("d/b.mdb")
Conn.Open
Set Rs = Server.CreateObject("ADODB.Recordset")
Response.write "SELECT * FROM comments WHERE comments.post = " & varp & ";"
Rs.Open "SELECT * FROM comments WHERE comments.post = " & varp & ";", conn, 1, 3
response.write ("<b><a href=""mailto:"& rs(email) &""">"& rs("name") &"</a></b><br>"& rs("body"))
response.write ("<form action=""savecom.asp?f=blog""><table><tr><td valign=""top"">Name:</td><td><input type=""text"" name=""name"" size=""40""></td></tr><tr><td valign=""top"">Email:</td><td><input type=""text"" name=""email"" size=""40""></td></tr><tr><td valign=""top"">Comment:</td><td><textarea name=""body"" cols=""25"" rows=""5""></textarea></td></tr></table></form>")
set Rs = nothing
set Conn = nothing
%>
|
|
|
|
01-28-2008, 02:45 AM
|
Re: make a blog/forum
|
Posts: 11,452
Location: Blackpool. UK
|
Ok, some things are NOT to be taken as literal code
varp=cint(Request.QueryString("p")) <> string
was pseudo code for:- varp is NOT a string.
The table column is a text type, so the database will expect to get a string value. The value received (varp) is an integer type so it will throw an exception, which is then handled by the ODBC driver and returned as an error.
To prevent this YOU have to send the correct TYPES to the database in the query. So to send an integer value as a string type it would be enclosed in SINGLE quotes. It would then be passed as #H38 instead of #H08.
So:
Code:
"SELECT * FROM comments WHERE comments.post = '" & varp & "';"
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
|
|
|
|
01-28-2008, 11:05 PM
|
Re: make a blog/forum
|
Posts: 77
|
Quote:
Originally Posted by chrishirst
Ok, some things are NOT to be taken as literal code
varp=cint(Request.QueryString("p")) <> string
was pseudo code for:- varp is NOT a string.
The table column is a text type, so the database will expect to get a string value. The value received (varp) is an integer type so it will throw an exception, which is then handled by the ODBC driver and returned as an error.
To prevent this YOU have to send the correct TYPES to the database in the query. So to send an integer value as a string type it would be enclosed in SINGLE quotes. It would then be passed as #H38 instead of #H08.
So:
Code:
"SELECT * FROM comments WHERE comments.post = '" & varp & "';"
|
Oh, silly me  .
So it finally works, thanks for all of your help. Do you have a website or anything, because you definitely deserve a link or two.
Last edited by Skeddles : 01-28-2008 at 11:45 PM.
|
|
|
|
01-29-2008, 03:07 AM
|
Re: make a blog/forum
|
Posts: 21
|
its working... they are great!
|
|
|
|
01-29-2008, 03:11 AM
|
Re: make a blog/forum
|
Posts: 11,452
Location: Blackpool. UK
|
 And more importantly, along the way you learn things that will stay with you.
In your original post (I get an email) you had a different problem which I take you fixed.
But you may run into a different issue with ASP & ODBC when reading MEMO/TEXT fields.
There is a bug in some versions of ODBC/MDAC that can be very irritating because how it manifests itself. I am not sure it even still exists because I automatically apply the workaround to every DB access I do.
I will do some testing before burdening you with possibly out of data info.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | | |