繁体   English   中英

PHP成就系统无法正常显示

[英]Php achievement system not displaying properly

我正在为网站创建成就系统。 提交第一条评论时,您会在屏幕的一角看到一条消息,其中显示了成就的名称和ID,几秒钟后它就会隐藏。

效果很好,除非您连续获得两个成就。 它一个接一个地显示两条消息,但它们在页面上具有第一个成就的ID。 如果我获得成绩5和8,它将显示两次数字5的消息,而不是5和8。

我该怎么办? 谢谢。

$user_id = mysqli_real_escape_string($connection, $_SESSION['user_id']);
if (isset($user_id)){

    function notification($connection, $trophy_id){
    $trophy_sql = "SELECT * FROM trophy WHERE trophy_id = '$trophy_id'";
    $trophy_result = mysqli_query($connection, $trophy_sql);

        if ($trophy = $trophy_result->fetch_assoc()){
        echo '
        <a href="../colection/achievement.php?id=' . $trophy['trophy_id'] . '">
        <div id="notification2" title="See trophy">

        <span class="trophy"><i class="fa fa-trophy ' . $trophy['trophy_color'] . '"></i></span>
        <span class="text">
        <span class="title">' . $trophy['trophy_name'] . '</span>
        <span class="subt">Text</span>
        </span><!-- title -->
        </div><!-- notification --></a>

        <script>
        $("#notification2").delay(1000).animate({width: "toggle"}).delay(3000).fadeOut(1000);
        </script>';
        }
    }

$number_comments_sql = "SELECT * FROM comments WHERE comments_user = '$user_id' AND comments_type IS NULL AND comments_deleted IS NULL";
$number_comments_result = mysqli_query($connection, $number_comments_sql);
$number_comments = mysqli_num_rows($number_comments_result);

$number_posts_sql = "SELECT * FROM comments WHERE comments_user = '$user_id' AND comments_position = '2' AND comments_deleted IS NULL";
$number_posts_result = mysqli_query($connection, $number_posts_sql);
$number_posts = mysqli_num_rows($number_posts_result);


for ($i=0;$i<3;++$i){
switch ($i){

    case 1:

        if ($number_comments > 0){
        $achiev_sql = "SELECT * FROM ad WHERE ad_type_id = 2 AND ad_user = '$user_id'";
        $achiev_result = mysqli_query($connection, $achiev_sql);
        $achiev = mysqli_num_rows($achiev_result);
            if ($achiev == 0){
                    notification($connection, 2);   
            }
        }break;


    case 2:

        if ($number_posts > 0){
        $achiev_sql = "SELECT * FROM ad WHERE ad_type_id = 3 AND ad_user = '$user_id'";
        $achiev_result = mysqli_query($connection, $achiev_sql);
        $achiev = mysqli_num_rows($achiev_result);
            if ($achiev == 0){
                    notification($connection, 3);               
            }
        }break; 


} // for
} // switch
} // end

当您查询结果时,每次您都基于userId进行查询,也就是说,每次查询时,您都将获得登录用户给出的所有注释,因此,如果用户创建id = 5的注释,那么您将收到相同的通知,如果用户创建id为8的评论,那么您将再次收到ID为5的评论的通知,因为即使该评论是由同一用户创建的。如果已提供通知,则为每个注释标记。

暂无
暂无

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

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