0

不知道如何表达标题对不起。基本上我有一个评论系统,它的工作原理非常简单,从数据库中选择帖子的 uid,然后从另一个数据库输出与该 UID 相关的评论。

评论系统的本质是每个发帖者都是匿名的,因此,很难跟踪你是否与同一个人交流,因此,我想让评论周围的 div 成为一个特定的颜色,并且该人对该帖子的每条评论都是该颜色。将用户评论联系在一起的唯一因素是 IP 地址。

到目前为止我的代码:

$sql = "SELECT * FROM anonpost_com WHERE uid = '$uid' ORDER BY date DESC";


$result = mysql_query($sql) or print ("Can't select entry from table anonpost.<br />" . $sql . "<br />" . mysql_error());

while($row = mysql_fetch_array($result)) {
    $date = date("l F d Y", strtotime($row['date']));
    $comment = stripslashes($row['comment']);
    $uid = ($row['uid']);
    $cid = ($row['cid']);
    $ip = ($row['ip']);


         ?>



<div id="comments" style="border:1px solid <?php echo $colour; ?>;">
<p><?php echo $comment; ?></p>
<h4>by <i>Anonymous</i> on <?php echo $date; ?></h4>
</div>
<?php
}
?>

$colour 来自: $colour = dechex(rand(0,10000000); 但我不确定如何使评论中同一 IP 的每个实例的 $colour 相同...

任何帮助,将不胜感激!

4

1 回答 1

1

我同意 IP 地址可能不是最好的解决方案,但要做到这一点:

$sql = "SELECT * FROM anonpost_com WHERE uid = '$uid' ORDER BY date DESC";

$colours = array();
$result = mysql_query($sql) or print ("Can't select entry from table anonpost.<br />" . $sql . "<br />" . mysql_error());

while($row = mysql_fetch_array($result)) {
    $date = date("l F d Y", strtotime($row['date']));
    $comment = stripslashes($row['comment']);
    $uid = ($row['uid']);
    $cid = ($row['cid']);
    $ip = ($row['ip']);
    if (!isset($colours[$ip])) {
        $colours[$ip] = dechex(rand(0,10000000);
    }
    $colour = $colours[$ip];


         ?>



    <div id="comments" style="border:1px solid <?php echo $colour; ?>;">
        <p><?php echo $comment; ?></p>
        <h4>by <i>Anonymous</i> on <?php echo $date; ?></h4>
    </div>
<?php
}
?>

请注意,每次页面加载时颜色都会改变。

于 2012-04-11T20:54:06.723 回答