Welcome Guest, Not a member yet? Register   Sign In
How to correctly update batch according to post.id
#1

So I currently have three tables.

ci_posts:
id, title, description.

ci_terms:
term_id,title,slug

ci_terms_relationship:
id, post_id, term_id

I have a function in which I can easily add terms to any post, the problem comes when I'm trying to update one of the post. Lets say I created a post with ONE term and I publish it, now I want to update it and put more(more than ONE) than the main term into it. 

PHP Code:
$terms $this->input->post('categories[]');;

 
           $data = array();

 
           foreach ($terms as $term){
 
               $data[] = array(
 
                   'post_id'  => $id,
 
                   'term_id'  => $term
 
                   'type'      =>  'category',
 
               );
 
           }

 
           $this->db->update_batch('ci_terms_relationship'$data'post_id'); 

The var $id comes from the id of the ci_posts table. As I said before, it currently updates the relationship with ONE term(as said above; from the add function which is not listed here).

And if I create a new post with at least 5 terms(different term_id) when updating it, it changes the term_id(all of them) to the first term_id of the selected terms.

Thanks in advance.
I do Front-End development most of the time 
Reply


Messages In This Thread
How to correctly update batch according to post.id - by kirasiris - 06-24-2018, 06:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB