In this code, after clicking the like button, the data is added in the database already. What I wanted to do now is I would like after adding the data, I will query the tota
Try this.
public function like_total(){
$id = $this->session->userdata('userID');
$upload = $this->input->get('like_id');
$data = array('like' => 1,
'userID'=>$id,
'uploadID'=>$_GET['like_id']);
$no_likes = $this->photoCheese_model->get_like_total($data,$upload);
$result['no_likes'] = $no_likes;
$this->output->set_content_type('application/json')->set_output(json_encode($result));
}
public function get_like_total($data,$uplaod){
$success = $this->db->insert('tbl_like',$data);
if($success){
$this->db->select('SUM(`like`) as no_likes');
$this->db->where('uploadID',$upload);
$query = $this->db->get('tbl_like');
$res = $query->row_array();
return $res['no_likes'];
}
return 0;
}