Stefany93 Posted June 27, 2012 Share Posted June 27, 2012 Hello colleagues, Please help me! Here is the issue: I have two tables in the Mysql DB one called posts and its columns are id title contents category_id datetime And I have another table whose name is comments and its fields are: id name comment So far I managed to display the comments from the databse, but the problem is that I want to display comments only that correspond to a specific post from the DB. Please, please help me, I have been trying to figure it out for weeks and still can't find the answer! Thank you! Best Regards Stefany Quote Link to comment https://forums.phpfreaks.com/topic/264863-how-to-display-comments-under-each-post/ Share on other sites More sharing options...
Bottyz Posted June 27, 2012 Share Posted June 27, 2012 you could add an additional field to the comments table such as postid and have it store which post number the comment belongs to? Quote Link to comment https://forums.phpfreaks.com/topic/264863-how-to-display-comments-under-each-post/#findComment-1357365 Share on other sites More sharing options...
Stefany93 Posted June 27, 2012 Author Share Posted June 27, 2012 Thank you, but is there any way I could increment this post_id automatically? Quote Link to comment https://forums.phpfreaks.com/topic/264863-how-to-display-comments-under-each-post/#findComment-1357456 Share on other sites More sharing options...
xyph Posted June 27, 2012 Share Posted June 27, 2012 Google up AUTO_INCREMENT Quote Link to comment https://forums.phpfreaks.com/topic/264863-how-to-display-comments-under-each-post/#findComment-1357461 Share on other sites More sharing options...
Stefany93 Posted June 27, 2012 Author Share Posted June 27, 2012 I tried AUTO_INCREMENT in the phpmyadmin but an errors occures telling me that only the primary key can auto - increment... Please tell me what to do? Quote Link to comment https://forums.phpfreaks.com/topic/264863-how-to-display-comments-under-each-post/#findComment-1357464 Share on other sites More sharing options...
mikosiko Posted June 27, 2012 Share Posted June 27, 2012 you are doing that wrong then. the suggested post_id field in your table comments must reference the column id in your table posts, if that field IS an AUTO-INCREMENT field you don't need to declare it again in the table comments Quote Link to comment https://forums.phpfreaks.com/topic/264863-how-to-display-comments-under-each-post/#findComment-1357470 Share on other sites More sharing options...
Drummin Posted June 27, 2012 Share Posted June 27, 2012 The table you had was probably fine for the comment table with for example id as the AUTO-INCREMENT field. You'll want to have that id field to identify the comment for updates etc. You just need to add the post_id field as noted and add this id when comment is added. Quote Link to comment https://forums.phpfreaks.com/topic/264863-how-to-display-comments-under-each-post/#findComment-1357481 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.