Displaying the data dynamically using Ajax

前端 未结 5 449
难免孤独
难免孤独 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条回答
  •  Happy的楠姐
    2021-01-13 12:52

    public function like_total(){
    $data = array('like' => 1,
                    'userID'=>$this->session->userdata('userID'),
                    'uploadID'=>$_GET['like_id']);
    
    $no_likes = $this->photoCheese_model->get_like_total($data,$this->input->get('like_id'));
    
    $result['no_likes'] = $no_likes;
    
     $this->output->set_content_type('application/json')->set_output(json_encode($result)); 
    }
    
    
    
    
        public function get_like_total($data,$this->input->get('like_id')){
        $success = $this->db->insert('tbl_like',$data);
    
        if($success){
        $this->db->select('SUM(`like`) as no_likes');
        $this->db->where('uploadID',$this->input->get('like_id'));            
    
        $query = $this->db->get('tbl_like');
    
        $res = $query->row_array();
    
        return $res['no_likes'];
        }
    
        return 0;
        }
    

提交回复
热议问题