1
'comments'테이블에서 코멘트를 삭제할 때 'posts'테이블의 코멘트 수량을 줄이려고합니다. 아래 코드를 확인하고 $ post_id 값을 얻을 수 있도록 도와 주시겠습니까? 나는 Codeigniter를 사용한다.Codeigniter 코멘트를 삭제하고 댓글 수를 줄입니다.
public function remove_comment($comment_id)
{
$this->db->where('id', $comment_id);
$query = $this->db->get('comments');
if ($query->num_rows() == 1) {
$this->db->where('id', $comment_id);
$this->db->delete('reviews');
$post_id = // grab the value from 'comments' table
$this->db->where('post_id', $post_id);
$this->db->set('comments', 'comments - 1', FALSE);
$this->db->update('posts');
return true;
} else {
return false;
}
}