PDA

View Full Version : mySQL, blog-type, and comments


Shahiro
August 19th, 2006, 03:09 PM
Just recently I taught myself PHP and mySQL, and my first project was making my front page of my site much like a blog, where I can make posts without editing html and uploading, editing them, and deleting them. That works great, I used a table in mySQL to store my posts, name, email, subject and all. Problem is, I'm having a problem figuring out how I'd add it so people can post comments for each seperate topic/post.

Would I create a seperate table for each post for comments?

Another question... I have the post fed from a textarea. The problem is, it doesn't register line breaks, so if I type out a post and start a new paragraph, it still all appears on the same line. How would I make it so it automatically inserts line breaks when I make the post? And if possible, remove the breaks and format it correctly in the textarea when I edit it.

oracle128
August 19th, 2006, 05:52 PM
Problem is, I'm having a problem figuring out how I'd add it so people can post comments for each seperate topic/post.

Would I create a seperate table for each post for comments?No. Just one table for all comments, with the following fields:
CommentID, BlogID (relates to the ID of a blog post), Date/Time (for sorting purposes, mainly), Name (name of the commenter), Comment
Also add email/homepage if you want.

Another question... I have the post fed from a textarea. The problem is, it doesn't register line breaks, so if I type out a post and start a new paragraph, it still all appears on the same line. How would I make it so it automatically inserts line breaks when I make the post?Before you get PHP to store it in the database, you need to edit it a bit. I'll leave the exact code up to you, but what you need to do is perform a string replace - finding Carriage Returns and replacing them with <br /> tags. Hint: lookup the PHP function str_replace.

When you edit the post, and have PHP pull the post content from the database, all you need to do is reverse the operation, replacing <br /> tags with carriage returns.

Shahiro
August 20th, 2006, 01:31 AM
Thanks, I figured something like that, but how do I recognize carriage returns in code, \n or?

Shahiro
August 20th, 2006, 04:38 AM
Nevermind, I finished both things. I've got working comments, and a form that parses newlines. Thanks! you helped heaps.

degsy
August 20th, 2006, 02:41 PM
I would recommend that you use a Rich Text textarea to submit your posts. It will submit them in HTML format.

http://www.fckeditor.net/