嘿伙计们,我有一个网站,其网址如下所示: www.domain.com/photos.php?id=(图片ID); 现在,我的问题是,如何使用 mysql 和 php 为每张图片添加注释。
最佳答案
您可能需要一个新表来将用户与评论与图片链接起来:
表格:评论
id (comment id), user (user id), picture (pic id), comment (text), date(timestamp w/default current time)
然后在显示图像后,再次查询任何评论:
$comments_query = mysql_query("SELECT comment FROM comments WHERE picture = $id");
while($comments_result = mysql_fetch_array($comments_query)){
echo($comments_result['comment']);
}
<小时/>
您可能还希望将每个用户的用户名链接到评论:
$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']);
}
关于php - 如何给php网站添加评论区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4571552/