Welcome Guest, Not a member yet? Register   Sign In
Send only selected data .. many-to-many relationship table.

So, I want to create a many-to-many relationship table in my database for which I decided to create a function which is supposed to let me send data with not problem.
PHP Code:
           // Create many-to-many relationship
           $taxonomy_list $this->Terms_model->get_list();

           foreach $taxonomy_list as $cat )
                   //do insert here
                   $data = array(
                       'term_taxonomy_id'  => $this->db->insert_id(),
                       'term_id'           => $cat->term_id,
                       'type'              => 'category',


           $relationship_list $this->Taxonomy_model->get_list();

           $data = array();

           foreach $relationship_list as $rel )
                   // Insert selected values
                   $data[] = array(
                       'post_id'           => $last_post_id,
                       'term_taxonomy_id'  => $rel->term_taxonomy_id,
                       'term_order'        => 0,

//            $this->Relationship_model->add($data);

So far it works great, the problem comes when selecting specific data (sometimes I just get to choose 1, sometimes 2,etc.).

The current function actually send all the values without taking into account that I just selected 1(maybe?).

Here are some pictures to clarify what I mean:

[Image: 45.jpg]

Second Pic:
[Image: 46.jpg]

third pic:

then in the post appear all three(or more depending on the number of categories that I have created).
[Image: 47.jpg]

I hope I could make myself clear.

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

Make a var_dump on categories and see what you are actually sending to your controller. If it's more then one (if only one selected) it's a javascript problem.

Theme © iAndrew 2016 - Forum software by © MyBB