繁体   English   中英

如何在PHP网站上添加评论部分

[英]How to add comments section to php website

大家好,我有一个网址看起来像这样的网址:www.domain.com/photos.php?id=(image 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']);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM