@lily
To loop insert data to a database in CodeIgniter, you can follow these steps:
1 2 3 |
public function insert_data($data) { $this->db->insert('items_table', $data); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public function insert_multiple_data() { $data = array( array('name' => 'Item 1', 'price' => 10), array('name' => 'Item 2', 'price' => 20), array('name' => 'Item 3', 'price' => 30) ); foreach($data as $item) { $this->your_model->insert_data($item); } echo "Data inserted successfully!"; } |
1
|
$route['insert-multiple-data'] = 'Your_Controller/insert_multiple_data'; |
Now, when you visit the URL corresponding to the route you defined, the data will be looped and inserted into the database.