View Full Version : Blog comments

10-03-2004, 02:41 AM
I want to implement a script on my site that would allow my users to add comments on my entries. The scripts that I have found on google have been to comment on the entire site, not per entry, or have needed javascript. I have an idea on how I would do it. Each entry would get an id that would correspond to the database, and then have each comment for that date be shown. But I don't know php/mysql well enough to do it.

I would like it so when the user clicks add a comment, they are taken to a page with the form fields to fill in up top and the comments from other people below them. And another link with for view the comments which lists my entry and has the comments below it.

So if anyone knows of one that uses php, mysql and no javascript, could you point me in the right direction.

10-03-2004, 07:15 AM
we could do it, but we'd need information on how your blog is setup. Do you use a service? Is it written yet? Is it a custom one you wrote? downloaded?


10-03-2004, 08:40 AM
I coded mostly everything. It's my own site, no services. My host gives me basicly any extension I want so that's not really an issue.
The basic set up is

<span class="entry">
October 2<sup>nd</sup>

Adding an id to the span would be easy.
Site : http://www.squirrelplayingtag.uni.cc
The php on the page is the links and the style changer.

10-05-2004, 12:02 PM
Uhm...hey Squirrel...lol

in the process of creating this, I'm going to end up with a complete blogging system. It should be modular enough to work with what you've got, though.

When I'm done, you'll need to create the comments table in your database and configure the script. Access should be fairly easy:

Example Link to add comment:

<a href="blog.php?id=127">Add Comment</a> | <?php print $entry->num_comments; ?> Comments

i'm almost done with just the comments part. I'll let u know when I'm finished.

10-06-2004, 08:50 PM
Wow thanks. I thought you had one and could just make a few changes, I didn't mean for you to make one. But if your going to thats awsome. Thank you so much.

10-08-2004, 03:56 AM
Ok. I figured I'd give you first crack at this code.

First, a few notes:

I haven't documented the class yet.
There are notes at the top of "Edit.class"....this is my to-do list...and it is growing. Such as:

The code needs a a *lot* of cleanup. Some of the functions need to be better defined with return values.
I have an init function...I need a destructor for the object
PHP 5 support (didn't know what u had, so I worked with PHP4 compat)
Several functions contain lots of similar code. This is usually an indication of poor design, and in this case, it is. I need probably need to rename the project to "Blog.class" with "entry.class" and "comments.class" as children and/or seperate classes.
A more concise style/template system
an additional template/style for the comments/single-entry display
It is never a good idea to allow public access of variables the way the script does. It should be rewritten to use a $instance->get() function
several other little things, that I need to fix

General Directions:
db_sql contains the sql to setup the database & 2 tables. Create a database called db_blog (or change the one in the file to match an existing one), and import the file.
db_info.php contains database connection options. These are in php to help prevent unauthorized viewing. You'll need to edit this.
blog_config.ini is the beginning of some of the blog specification options. This isn't documented yet, but everything uses a template of some sort (the [files] section)
blog.php is the starting point. You'd go to http://server/directory/blog.php to get things started, if using a full system
All other files not (except Edit.class) can be edited and changed. These were created to give you an idea as to what the links should look like.
If you're having problems integrating with your existing system, you'll probably need to edit the SQL statements in places like the display_comments function in Edit.class.

Note...this system doesn't have any way to actually add blog entries. lol. I added them manually through mysql_front. There is also no validity checking, and it's lacking in just so many areas I'd rather not go into it.

But there you have it. I hope to add an admin panel, user authentication, and an install script for the entire blog. Anyways...just figured I'd give you something to maybe get started with.


ps. it's attached in the zip file, in case you missed it.

pps. use at own risk :P

ppps. consider this version 0.4