@Caspergreen

Занесение данных в две таблицы, Codeigniter. Как?

Заношу данные в бд, лезет нотис:
Message: Array to string conversion
Код:
$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(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 ( [series_id] => 35 [genre_id] => Array ( [0] => 6 [1] => 7 ) )
  • Вопрос задан
  • 278 просмотров
Решения вопроса 1
AloneCoder
@AloneCoder
[object Object]
$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);
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы