Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何向php网站添加评论部分_Php_Mysql_Comments - Fatal编程技术网

如何向php网站添加评论部分

如何向php网站添加评论部分,php,mysql,comments,Php,Mysql,Comments,嘿,伙计们,我有一个网站的url看起来有点像这样: 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) 然后在显示图像后,对任何注释执行另一个

嘿,伙计们,我有一个网站的url看起来有点像这样: 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']);
}

您可能需要一个新表来链接用户和带有图片的注释:

表:评论

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']);
}

评论是来自用户还是每张图片一条评论?评论是来自用户还是每张图片一条评论?