2014-10-11 2 views
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; 
     } 
    } 

답변

1

enter image description here 그럼 당신이 먼저 가져올 필요가, 당신이 ->row()을 사용할 수 있습니다 여기

은 '의견'테이블입니다.

$query = $this->db->get('comments'); 
$result = $query->row(); 
$post_id = $result->post_id; 
관련 문제