I want to insert data in database table using loop. For this I first need to get data of Account_id from user profile table. When user is registered with my website, his/her name table is create automatically, I am storing this table name in Account_id. that's why I must need this field.
First I get all registered users Account_id value. And then I am searching this table using for loop in model.
After I find this table, the row should be inserted, which is created dynamically like
$data = array(
'Paper_Name' => $paper_name,
'Paper_Type' => $paper_type,
'paid_type' => $paid_type
);
Here is my model code.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class create_main_table_model extends CI_Model {
function login($data){
$query = $this->db->insert('main_table', $data);
$update_userdata = $this->db->select('Account_id')->from('userprofile')->get();
for($i =0; $i < $update_userdata->num_rows(); $i++){
$query = $this->db->insert($update_userdata[$i], $data);
}
return ($this->db->affected_rows() > 0) ? true : false;
}
}
?>
I want to Insert data to tables which is available in Account_id.
If this is possible with other way then please tell me.