CodeIgniter Forums
Send only selected data .. many-to-many relationship table. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Send only selected data .. many-to-many relationship table. (/showthread.php?tid=70373)



Send only selected data .. many-to-many relationship table. - kirasiris - 04-01-2018

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',
 
                   );
 
           }

 
           $this->Taxonomy_model->add($data);

 
           $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);
 
           $this->db->insert_batch('ci_terms_relationship'$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.


RE: Send only selected data .. many-to-many relationship table. - jreklund - 04-01-2018

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.