0

Hey guys, I have a website that has a url that looks sorta like this: www.domain.com/photos.php?id=(image id); Now, my question is, how can I add comments to each picture using mysql and php.

1
  • Would the comments be from users or one comment per picture? Commented Dec 31, 2010 at 17:59

1 Answer 1

3

You will probably want a new table to link the user with the comment with the picture:

table: comments

id (comment id), user (user id), picture (pic id), comment (text), date(timestamp w/default current time)

Then after you show the image, do another query for any comments:

$comments_query = mysql_query("SELECT comment FROM comments WHERE picture = $id");
while($comments_result = mysql_fetch_array($comments_query)){
   echo($comments_result['comment']);
}

You will also probably want to link each user's username to the comment as well:

$comments_query = mysql_query("SELECT comments.comment, users.username, comments.date FROM comments INNER JOIN users ON comments.user = users.id WHERE comments.picture = $id");
while($comments_result = mysql_fetch_array($comments_query)){
    echo($comments_result['date']);
    echo($comments_result['username']);       
    echo($comments_result['comment']);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.