在我最近的工作中,我正在制作一个“喜欢/不喜欢”按钮。
但是...当执行“不喜欢”操作时,他们不会重新加载选择查询。
这是我的代码:
public function likePost($status = null){
$data = json_decode($this->input->raw_input_stream, true);
$this->load->database();
$query = $this->db->query("SELECT *, COUNT(posts_like.idPost) AS total_likes FROM posts_like WHERE idPost = " . $data['idPost'] . " AND idUser = " . $data['idUser'] . " GROUP BY posts_like.idPost;")->result_array();
if($query){
if($status != 'new'){
$this->load->database();
// $this->db->where('idPosts_like', $query[0]['idPosts_like']);
// $this->db->delete('posts_like', array('idPosts_like', $query[0]['idPosts_like']));
$this->db->query("DELETE FROM posts_like WHERE idPosts_like = " . $query[0]['idPosts_like'] . ";");
$response = ['status' => true, 'results' => $query, 'messege' => 'deleted'];
}else{
$response = ['status' => true, 'results' => $query, 'messege' => 'liked'];
}
}else{
$this->db->insert('posts_like', $data);
$this->likePost($status = 'new');
}
header('Content-type: application/json');
die(json_encode($response));
}
有人可以帮助我吗? 非常感谢!