php - Insert array batch in codeigniter -
i want insert array array below format, how this, i've try insert batch also, doesn't work.
array(4) { ["notification_title"]=> array(2) { [0]=> string(35) "hello! have news you." [1]=> string(35) "hello! have news you." } ["notification_message"]=> array(2) { [0]=> string(81) "now can choose 3 types of advertisers wish collaborate." [1]=> string(95) "saat ini anda sudah dapat memilih maksimal 3 (tiga) tipe iklan untuk dipasang pada mobil anda. " } ["notification_type"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "1" } ["notification_language"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } }
i've try this, doesn't work
public function save($data) { $this->db->insert_batch($this->table, $data); }
error message
<h1>a database error occurred</h1> <p>error number: 1064</p><p>you have error in sql syntax; check manual corresponds mysql server version right syntax use near '0, 1) values ('hello! have news you.','hello! have news ' @ line 1</p><p>insert `ads_notification` (0, 1) values ('hello! have news you.','hello! have news you.'), ('now can choose 3 types of advertisers wish collaborate.','saat ini anda sudah dapat memilih maksimal 3 (tiga) tipe iklan untuk dipasang pada mobil anda. '), ('1','1'), ('1','2')</p><p>filename: c:/xampp/htdocs/movads/application/models/modelnotifications.php</p><p>line number: 127</p> </div>
this 1 print_r statement
--- print_r statement ---
array ( [notification_title] => array ( [0] => keep weekly minimum distance monitor. [1] => keep weekly minimum distance monitor. ) [notification_message] => array ( [0] => found out driving below weekly minimum distance. keep driving safely , increase driving distance meet minimum requirements. [1] => anda masih belum memenuhi target jarak minimum mingguan. tetap menyetir dengan aman dan tingkatkan jarak mingguan anda. tetap semangat! ) [notification_type] => array ( [0] => 2 [1] => 2 ) [notification_language] => array ( [0] => 1 [1] => 2 ) )
$post_array = array( "notification_title"=>array("hello! have news you.","hello! have news you."), "notification_message"=>array("now can choose 3 types of advertisers wish collaborate.","now can choose 3 types of advertisers wish collaborate."), "notification_type"=>array('1','1'), "notification_language"=>array('1','1') ); $data = array(); $i = 0; foreach($post_array $key=>$val) { $i = 0; foreach($val $k=>$v) { $data[$i][$key] = $v; $i++; } } echo '<pre>'; print_r($data);
so array below , can use insert batch
$data = array( array( 'notification_title'=> 'hello! have news you', 'notification_message'=> 'now can choose 3 types of advertisers wish collaborate.', 'notification_type'=>'1', 'notification_language'=>'1' ), array( 'notification_title'=> 'hello! have news you', 'notification_message'=> 'now can choose 3 types of advertisers wish collaborate.', 'notification_type'=>'1', 'notification_language'=>'1' ), );
here key column name of table , than
$this->db->insert_batch('mytable', $data);
hope you..
Comments
Post a Comment