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:
Second Pic:
third pic:
then in the post appear all three(or more depending on the number of categories that I have created).
I hope I could make myself clear.
Thanks in advance.
I do Front-End development most of the time