我正在为网站创建一个成就系统。当您提交第一条评论时,您可以在屏幕的一角看到一条消息,其中显示了成就的名称和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
答案 0 :(得分:0)
当您查询结果时,每次基于userId进行查询时,每次查询时都会获得登录用户给出的所有注释,因此如果用户使用id创建注释如果用户创建id = 8的注释,那么您将收到相同的通知,然后您将再次收到id为5的注释的通知,因为即使该注释是由同一用户创建的。如果已提供通知,您可以为每条评论设置一个标记。