imperium2335 Posted June 19, 2009 Share Posted June 19, 2009 Hi, what is the best way to store comments in a Mysql database? I have image pages each with a unique ID number in the database, my first idea is to create a new column and have every comment for a given image stored in that field and separated by a symbol combination. This seems crude, is there a better way? I would also like to store the users name and the date they left the comment. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/162861-storing-comments-in-mysql/ Share on other sites More sharing options...
RussellReal Posted June 19, 2009 Share Posted June 19, 2009 no.. make a comments table, and have the following fields comment_id | image_id | user_id | comment Quote Link to comment https://forums.phpfreaks.com/topic/162861-storing-comments-in-mysql/#findComment-859364 Share on other sites More sharing options...
xtopolis Posted June 19, 2009 Share Posted June 19, 2009 Read this http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html And use a one to many relationship [1 picture -< many comments] Quote Link to comment https://forums.phpfreaks.com/topic/162861-storing-comments-in-mysql/#findComment-859365 Share on other sites More sharing options...
imperium2335 Posted June 19, 2009 Author Share Posted June 19, 2009 So how would I relate each comment to what image_id? Each image will have more than one comment. Quote Link to comment https://forums.phpfreaks.com/topic/162861-storing-comments-in-mysql/#findComment-859390 Share on other sites More sharing options...
RussellReal Posted June 19, 2009 Share Posted June 19, 2009 yes.. $id = (int) $_GET['id']; mysql_query("SELECT users.username, comments.comment FROM comments JOIN users ON (comments.user_id = users.id) WHERE image_id = '{$id}'"); Quote Link to comment https://forums.phpfreaks.com/topic/162861-storing-comments-in-mysql/#findComment-859391 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.