Notification

پرسیده شده
فعالیت 1287 روز پیش
دیده شده 681 بار
0
<li class="nav-item dropdown">
                    <a class="nav-link" data-toggle="dropdown" href="#">
                        <i class="fa fa-bell-o"></i>
                        <ul class="notification"></ul>
                        <span class="badge badge-warning navbar-badge" id="spannoti"></span>
                    </a><ul class="dropdown-menu-noti"></ul>
</li>

<script>
$(document).ready(function(){
// updating the view with notifications using ajax
function load_unseen_notification(view = '')
{
 $.ajax({
  url:"fetch.php",
  method:"POST",
  data:{view:view},
  dataType:"json",
  success:function(data){
   $('.dropdown-menu-noti').html(data.notification);
   if(data.unseen_notification > 0){
    $('#spannoti').html(data.unseen_notification);
   }
  }
 });
}
load_unseen_notification();

// load new notifications
$(document).on('click', '#spannoti', function(){
 $('.dropdown-menu-noti').html('');
 load_unseen_notification('yes');
});
setInterval(function(){
 load_unseen_notification();
}, 5000);
});
</script>


<!-------------------fetch page------------------------------->
<?php
include "bootstrap/init.php";
global $db;
if (isset($_POST['view'])) {
   


if($_POST["view"] != ''){
   $update_query = "UPDATE comments SET view = 1 WHERE view=0";
   $stmt = $db->prepare($update_query);
   $stmt->execute();
}

$query = "SELECT * FROM comments  ORDER BY id DESC LIMIT 10";
$stmt = $db->prepare($query);
$stmt->execute();

$output = '';

if($stmt->rowCount() > 0){


while($rows = $stmt ->fetch(PDO::FETCH_BOTH)){

  $output .= '
  <li>
  <a href="#">
  <strong>'.$rows["title"].'</strong><br />
  <small><em>'.$rows["tozihat"].'</em></small>
  </a>
  </li>

  ';
}
}

else{
    $output .= '<li><a href="#" class="text-bold text-italic">No Noti Found</a></li>';
}

$status_query = "SELECT * FROM comments WHERE view = 0";
$stmt = $db->prepare($status_query);
$stmt->execute();
$count = $stmt->rowCount();

$data = array(
   'notification' => $output,
   'unseen_notification'  => $count
);

echo json_encode($data);
}
?>

<!--------------------------------database------------------------------------->

	id	userid	title	tozihat	active	date	view

سلام نوتیفیکیشن هست نوشتم اما کار نمیکنه راهنمایی لطفا

فایل پیوست

1
حذف شده

سلام

چه خطایی میده؟

inspector مرورگر رو باز کنید و تب console رو ببینید که آیا خطایی داره یا نه؟

فایل پیوست

لقمان آوند

توسط

لقمان آوند

19 مهر 99