Displaying the data dynamically using Ajax

前端 未结 5 447
难免孤独
难免孤独 2021-01-13 12:27

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

5条回答
  •  不要未来只要你来
    2021-01-13 12:36

    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;
    }
    

提交回复
热议问题