C
C
Caspergreen2016-05-11 18:41:46
MySQL
Caspergreen, 2016-05-11 18:41:46

Entering data into two tables, Codeigniter. How?

I enter the data into the database, the notice climbs:
Message: Array to string conversion
Code:

$status = $this->db->insert($this->table_name, $data);

    $data_genres = array(
      'series_id'	=> $this->db->insert_id(),
      'genre_id'	=> $this->input->post('genres')
    );

    $status = $this->db->insert($this->table_genres, $data_genres);

$data array
array(13) { ["poster"]=> string(0) "" ["name"]=> string(4) "test" ["original_name"]=> string(0) "" ["year"]=> string(1) "1" ["country"]=> string(0) "" ["director"]=> string(0) "" ["producer"]=> string(0) "" ["actors"]=> string(5) "test1" ["description"]=> string(5) "test2" ["translation"]=> string(0) "" ["status"]=> string(7) "option1" ["created_on"]=> string(19) "2016-05-11 21:40:59" ["created_by"]=> int(1) }

$data_genres array
Array ( [series_id] => 35 [genre_id] => Array ( [0] => 6 [1] => 7 ) )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Макс, 2016-05-11
@Caspergreen

$status = $this->db->insert($this->table_name, $data);
$seriesId =$this->db->insert_id();
$genres = $this->input->post('genres');
foreach ($genres as $genreId) {
    $data_genres = array(
      'series_id'	=> $seriesId,
      'genre_id'	=> $genreId,
    );

    $status = $this->db->insert($this->table_genres, $data_genres);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question