Welcome Guest, Not a member yet? Register   Sign In
Delete cascade ?
#3

(06-12-2017, 04:42 AM)tonny16 Wrote: Hello,
I have an article table and a comment table. I hope that the comments of the article also disappear, how to do?

Thank you in advance

PHP Code:
$data = array(
   'deleted' => 1
);

$this->db->where('article_id'$article_id);
$this->db->update('article'$data); 

i prefer the soft delete. After x-months you can delete the rows.

If you use foreign keys you only need to delete the article (on delete cascade)

http://www.mysqltutorial.org/mysql-foreign-key/


if not: delete first the comments then the article

PHP Code:
$this->db->where('article_id'$article_id);
$status $this->db->delete('comments');
...
$this->db->where('article_id'$article_id);
$this->db->delete('article');
.... 
Reply


Messages In This Thread
Delete cascade ? - by tonny16 - 06-12-2017, 04:42 AM
RE: Delete cascade ? - by skunkbad - 06-12-2017, 08:34 AM
RE: Delete cascade ? - by Paradinight - 06-12-2017, 11:23 AM
RE: Delete cascade ? - by tonny16 - 06-14-2017, 07:19 AM
RE: Delete cascade ? - by rtenny - 06-15-2017, 08:23 AM
RE: Delete cascade ? - by rtenny - 06-15-2017, 08:27 AM
RE: Delete cascade ? - by tonny16 - 06-17-2017, 12:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB