使用PHP和Jquery的通知消息

时间:2015-09-02 07:00:38

标签: jquery

在我的应用程序的标题中,我有通知消息图标。

例如,当新记录插入表格时,必须向管理员显示通知消息,如下所示:

image1

如果我切换按钮,它看起来像这样:

enter image description here

但问题是,当我点击通知按钮时,它会显示数据,但通知计数不会重置为零。

当我点击通知链接时,我需要的是,通知数量应该重置为零。

它应该如下图所示

image3

这是我的代码:

<!-- Messages: style can be found in dropdown.less-->
                <li class="dropdown messages-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" id="notify-comet">
                        <i class="fa fa-envelope-o"></i>
                        <span class="label label-success" id="not-count">
                            <?php
                                $count = Delay::find()
                                        ->where(('id') !== 0)
                                        ->orderBy('id')
                                        ->count();  
                                echo "$count";
                            ?>
                        </span>
                    </a>
                    <ul class="dropdown-menu">
                        <li class="header">You have <?php echo "$count" ?> messages</li>
                        <?php
                            $qry = Delay::find()->all();
                            foreach ($qry as $key => $value) 
                            { 
                        ?>
                            <div class="delay-notification">
                            <ul class="menu">
                                <li><a href="index.php?r=delay"><?php echo $value->claimer_name; ?> &nbsp <?php echo $value->company_name; ?></a></li>
                            </ul>
                            </div>
                        <?php  
                            $i = 1;
                            if ($i++ == 4) break;
                            }
                        ?>

                        <li class="footer"><a href="index.php?r=delay">See All Messages</a></li>
                    </ul>
                </li>

                <?php
                    }
                ?>

3 个答案:

答案 0 :(得分:1)

使用jQuery绑定.messages-menu

上的事件
jQuery(document).ready(function($){
   $('#notify-comet').on('click', function(e){
        $("#not-count").html("0");
   })
})

每次打开下拉列表时,它都会将计数器重置为0.

答案 1 :(得分:0)

单击链接或按钮(显示计数)时执行一个简单的操作调用ajax函数,该函数将计数重置为零或简单j查询可以通过保留该范围的值来为您执行此操作

答案 2 :(得分:0)

<?php
session_start();
include("../connect.php");
$user=$_SESSION['user'];
if(empty($user))
{
    header("location:index.php");
}
else{
$query_not="SELECT count(status) AS sum FROM `user_leave_details` where status='1' Or status='4' or status='5'";
$result=mysqli_query($bd,$query_not);
while($arr=mysqli_fetch_array($result))
{   
$sum=$arr['sum'];
}   
?>
<html>
<head>
<li class="dropdown messages-menu">
<a href="" class="dropdown-toggle"><span style="color:white"><i class='fa fa-comment-o'  title="Notification"></i></span>
<span class="badge" style="color:#FF0000">
<?php if(empty($_POST['hide']))
{ 
echo $sum;
}
else
{
echo $sum=0;
}?>
</span></a>                                 
<ul style="display: none;" class="dropdown-menu bold">
<?php
$query="SELECT * FROM user_leave_details WHERE status='1' Or status='4' or status='5'";
$sl_no=1;
$result=mysqli_query($bd,$query);
if(mysqli_num_rows($result)>0)
{                                                       while($row=mysqli_fetch_array($result))
                                                 { 
                                                 $user_id=$row['leave_id'];
                                                 $user_name=$row['user_name'];
                                                 $no_days=$row['no_leave'];
                                                 $leave_from=$row['leave_from'];
                                                 $leave_to=$row['leave_to'];
                                                 $status=$row['status'];
                                            ?>
                                         <li name='hlo'><?php echo "<a href='admin_approved.php?reg_id=$user_id' id='hide'' name='hide'>";?><?php if($status==1){echo $user_name." request permission for ".$no_days. " day/days leave from ".$leave_from ." to ".$leave_to;}else if($status==4){echo $user_name." leave reduced from ".$leave_from." to".$leave_to ;}else if($status==5){echo $user_name." cancel for the leave from ".$leave_from." to ".$leave_to;}echo " </a>"; ?> </li>
                                          <?php
                                          if(isset($_POST['hlo']))
                                            {
                                                echo $sum=0;
                                            }
                                            }

                                            }
                                        ?>

                                </ul>
                            </li> 
</head>
</html>
connect.php
<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";$mysql_database = "";        $bd=mysqli_connect($mysql_hostname,$mysql_user,$mysql_password,$mysql_database);
?>