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
After all the helps and research. This is the running code of this problem.
In the View:
likes • dislikes •'>Delete Picture
Like
Javascript:
Controller:
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']);
$result = $this->photoCheese_model->get_like_total($data,$upload);
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($result));
return $result;
}
Model:
public function get_like_total($data,$upload){
$success = $this->db->insert('tbl_like',$data);
//Query the total likes
if($success){
$this->db->select()->from('tbl_like');
$this->db->where('uploadID',$upload);
$this->db->where('like !=',2);
$query = $this->db->get();
return $query->num_rows();
}
return 0;
}
This code runs perfectly now. Thanks for the help anyway.