1
從'評論'表中刪除評論時,我想減少'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;
}
}