title: how to update one table based on another table ID codeigniter
body: <p>I have two tables, first table is directly associated with the second table. I'm using codeigniter and mysql as my database system. </p>
  
  <p>My first table called <code>exam</code> and its structure on below picture:</p>
  
  <p><a href="https://i.stack.imgur.com/TUbKi.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TUbKi.jpg" alt="exam_tbl"></a></p>
  
  <p>This is my second table called <code>exam_assign_classes</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/s27RE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s27RE.jpg" alt="exam_assign_tbl"></a></p>
  
  <p>How do I update the second table based on first table id. Sometimes in the edit page a user can add assigned batch or remove number of batch. I have tried counting numbers of rows with matching ids and delete those from second table and then re-insert it but it seems so bad practice?</p>