Php 如何在ul中为特定人员消息的计数消息设置条件?
这是我从数据库中获取数据的代码 型号:-Php 如何在ul中为特定人员消息的计数消息设置条件?,php,html,codeigniter,Php,Html,Codeigniter,这是我从数据库中获取数据的代码 型号:- public function fetch_data($v) { if($v != '') { $this->db->set('chat_status', '0'); $this->db->where('chat_status','1'); $this->db->upd
public function fetch_data($v)
{
if($v != '')
{
$this->db->set('chat_status', '0');
$this->db->where('chat_status','1');
$this->db->update('chat');
}
$this->db->select("receiver_id");
$this->db->from("chat");
$this->db->where("chat_status", "1");
$this->db->order_by("id", "DESC");
$this->db->limit(1);
$result = $this->db->get();
$output = '';
$this->db->select("receiver_id");
$this->db->from("chat");
$this->db->where("chat_status", "1");
$this->db->order_by("id", "DESC");
$this->db->limit(1);
$result1 = $this->db->get();
$count=$result1->num_rows();
$data= array('unseen_notification'=>$count);
return json_encode($data);
}
public function index()
{
$v=$this->input->post('view');
echo $op= $this->Notify_Model->fetch_data($v);
return $op;
}
$(document).ready(function(){
function load_unseen_notification(view = '')
{
$.ajax({
url:"<?php echo base_url();?>Notify/index",
method:"POST",
data:{"view":view},
dataType:"json",
success:function(data)
{
$('.dropdown-menu').html(data.notification);
$('.count').show();
if(data.unseen_notification > 0)
{
$('.count').html(data.unseen_notification);
} else if(data.unseen_notification == ''){
$('.count').hide();
}
}
});
}
load_unseen_notification();
$(document).on('click', '.dropdown-toggle', function(){
$('.count').html('');
load_unseen_notification('yes');
});
setInterval(function(){
load_unseen_notification();
}, 1000);
});
这是我的控制器
控制器:-
public function fetch_data($v)
{
if($v != '')
{
$this->db->set('chat_status', '0');
$this->db->where('chat_status','1');
$this->db->update('chat');
}
$this->db->select("receiver_id");
$this->db->from("chat");
$this->db->where("chat_status", "1");
$this->db->order_by("id", "DESC");
$this->db->limit(1);
$result = $this->db->get();
$output = '';
$this->db->select("receiver_id");
$this->db->from("chat");
$this->db->where("chat_status", "1");
$this->db->order_by("id", "DESC");
$this->db->limit(1);
$result1 = $this->db->get();
$count=$result1->num_rows();
$data= array('unseen_notification'=>$count);
return json_encode($data);
}
public function index()
{
$v=$this->input->post('view');
echo $op= $this->Notify_Model->fetch_data($v);
return $op;
}
$(document).ready(function(){
function load_unseen_notification(view = '')
{
$.ajax({
url:"<?php echo base_url();?>Notify/index",
method:"POST",
data:{"view":view},
dataType:"json",
success:function(data)
{
$('.dropdown-menu').html(data.notification);
$('.count').show();
if(data.unseen_notification > 0)
{
$('.count').html(data.unseen_notification);
} else if(data.unseen_notification == ''){
$('.count').hide();
}
}
});
}
load_unseen_notification();
$(document).on('click', '.dropdown-toggle', function(){
$('.count').html('');
load_unseen_notification('yes');
});
setInterval(function(){
load_unseen_notification();
}, 1000);
});
这是我在视图中调用通知的ajax和视图
Ajax:-
public function fetch_data($v)
{
if($v != '')
{
$this->db->set('chat_status', '0');
$this->db->where('chat_status','1');
$this->db->update('chat');
}
$this->db->select("receiver_id");
$this->db->from("chat");
$this->db->where("chat_status", "1");
$this->db->order_by("id", "DESC");
$this->db->limit(1);
$result = $this->db->get();
$output = '';
$this->db->select("receiver_id");
$this->db->from("chat");
$this->db->where("chat_status", "1");
$this->db->order_by("id", "DESC");
$this->db->limit(1);
$result1 = $this->db->get();
$count=$result1->num_rows();
$data= array('unseen_notification'=>$count);
return json_encode($data);
}
public function index()
{
$v=$this->input->post('view');
echo $op= $this->Notify_Model->fetch_data($v);
return $op;
}
$(document).ready(function(){
function load_unseen_notification(view = '')
{
$.ajax({
url:"<?php echo base_url();?>Notify/index",
method:"POST",
data:{"view":view},
dataType:"json",
success:function(data)
{
$('.dropdown-menu').html(data.notification);
$('.count').show();
if(data.unseen_notification > 0)
{
$('.count').html(data.unseen_notification);
} else if(data.unseen_notification == ''){
$('.count').hide();
}
}
});
}
load_unseen_notification();
$(document).on('click', '.dropdown-toggle', function(){
$('.count').html('');
load_unseen_notification('yes');
});
setInterval(function(){
load_unseen_notification();
}, 1000);
});
$(文档).ready(函数(){
函数加载\未查看\通知(视图=“”)
{
$.ajax({
url:“通知/索引”,
方法:“张贴”,
数据:{“视图”:视图},
数据类型:“json”,
成功:功能(数据)
{
$('.dropdown menu').html(data.notification);
$('.count').show();
如果(data.unseen_通知>0)
{
$('.count').html(data.unseen_通知);
}else if(data.unseen_通知=“”){
$('.count').hide();
}
}
});
}
加载未查看的通知();
$(文档).on('单击',')。下拉切换',函数(){
$('.count').html('');
加载未查看的通知(“是”);
});
setInterval(函数(){
加载未查看的通知();
}, 1000);
});
这是我的视图,我在其中调用了通知计数:
<ul class="users-list clearfix">
<?php
$this->db->select();
$this->db->from("chat");
$this->db->where("sender_id", $this->session->userdata('id'));
$this->db->where("chat_status", "1");
$this->db->order_by("id", "DESC");
$result = $this->db->get();
if($result)
{
?>
<li style="width: 0px;padding: 0px;">
<span class="label label-pill count" style="border-radius:10px;color: black;"></span>
</li>
<?php
}
?>
<?php if(!empty($adminslist)){
foreach($adminslist as $v):
?>
<li class="selectVendor" id="<?=$v['id'];?>" title="<?=$v['fname'];?>">
<img src="<?=base_url('/assets/uploads/' . $v['img']);?>" alt="<?=$v['fname'];?>" title="<?=$v['fname'];?>">
<a class="users-list-name" href="#"><?=$v['fname'];?></a>
<!--<span class="users-list-date">Yesterday</span>-->
</li>
<?php endforeach;?>
<?php }else{?>
<li>
<a class="users-list-name" href="#">No Admin Find...</a>
</li>
<?php } ?>
</ul>
宽度:0px;填充:0px;“>
“title=”“>
-
我如何在此为特定人员设置计数消息的条件..我尝试了此代码,但不起作用,我在视图模型中设置了条件。您不应该通过接收方id而不是发送方来查询通知,我的意思是代替
$this->db->where(“发送方id”,$this->session->userdata('id'))
它不应该像$this->db->where(“receiver_id”,“$this->session->userdata('id'));
?我试过了,但计数会随着所有用户而增加,而不是特定用户让您的视图执行数据库操作一开始就有点根本错误……好吧,让我检查一下