0

I'm facing an issue in updating rows in mysql table. I'm currently working on social media website. There's a notification table where we've all users notification. For example "John liked your post, Sara commented on your post" Just like this

Table structure is given below.

enter image description here

As you can see i have a column "IsRead". If the user click on "Mark all as read button" a query executes.

UPDATE notification SET isRead = 1 WHERE toUser = $id

When i execute this query it takes about 2 minutes or above and at the end it says connection to server has been lost. Error snap is attached below

enter image description here

Please suggest me what's the right way to create a table for notification. My created table structure is given above.

This is my javascript code:

function markAsRead(){
$('.notifications-area').html('<li><center>Noting to display</center></li>');
$('.list-notification').html('<li><center>Noting to display</center></li>');
$('#countNotifications').html(0);
$('#countNotifications1').html(0);
$.ajax({
        type: 'ajax',
        method:'POST',
        url: "<?php echo site_url()?>/Main/markAsRead",
        datatype:"JSON",
        success:function(responce)
        {   
            
        },
        error:function(e)
        {
           console.log(e);
        }
    });
}

My Controller:

public function markAsRead(){
    
    $data=$this->m->markAsRead();
     echo json_encode($data);
}

Model:

public function markAsRead(){
    $userid = $this->session->userdata('userid');
    $query = $this->db->query("UPDATE notification SET isRead = 1 WHERE toUser = $userid and isRead = 0");
    return $query;
}
Abdul Rehman
  • 25
  • 11

0 Answers0