Jump to content

Cant get the comment to display in the right order


divinedesigns1

Recommended Posts

hey guys, im having a little problem getting the comments for 2 different post, to match up. i have comment 1 that belong to post 1, and comment 2 that belong to post 2, but it doesnt stay on the post it belongs, instead i end up with comment 1 n 2 on post 1 n 2. how can i get this right? i try $_get[id] but that still didnt work either. any idea?

Link to comment
Share on other sites

That's a pretty abstract question without seeing any code. The obvious answer is that you need a field in your database that says which post each comment belongs to, and when you display a post you use the post ID to get the comments for that post. That's about all there is to it. I can't guess why it's not working for you without seeing what you're actually doing. I can tell you that PHP variables are case-sensitive, you need to use $_GET and not $_get.

Link to comment
Share on other sites

just to dig a little deeper, when you display a post on a page, one technique is have its unique id from the DB (say post_id, and ideally the primary key of the posts table) as a hidden field in the form that submits the comments. When someone comments, you add the comment to the comments table, and fill in a "post_id" column in the comments table, which is the value of that hidden field, and is a foreign key to the post table. This maps comments to posts. So whenever you display a post, you look in the comments table for all comments with a post_id that matches the post_id from the posts table.

Edited by thescientist
Link to comment
Share on other sites

just to dig a little deeper, when you display a post on a page, one technique is have its unique id from the DB (say post_id, and ideally the primary key of the posts table) as a hidden field in the form that submits the comments. When someone comments, you add the comment to the comments table, and fill in a "post_id" column in the comments table, which is the value of that hidden field, and is a foreign key to the post table. This maps comments to posts. So whenever you display a post, you look in the comments table for all comments with a post_id that matches the post_id from the posts table.
ok thanks, ill try that...but i have the post_id already in the comment tabel in the db, but ill try this one and see sup thanks
Link to comment
Share on other sites

well, you didn't give us any code, so we had no idea what you had already implemented. It's always just easier to give code for programming problems in general.

Edited by thescientist
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...