if we can input a user id order by auto increment ++, in a controller, some a function ..
i have a function callback_get_user_id(param)
previously a define user_model :
models/user_model.php
public function getId() { $q = $this->db->query("select MAX(RIGHT(user_id,5)) as kd_max from tb_user"); $kd = ""; if($q->num_rows()>0) { foreach($q->result() as $k) { $tmp = ((int)$k->kd_max)+1; $kd = sprintf("%05s", $tmp); } } else { $kd = "00001"; //auto increment } return "USR".$kd; }
and then ...load function in user_model : $this->user_model->getId();
public function get_user_id($user_id) { $this->load->model('user_model'); $user_id = $this->user_model->getId(); return '<input type="text" name="id_user" value="'.$user_id.'" readonly/>'; }
and,
public function callback_phone($phone) { return '<input type="text" maxlength="12" value="'.$phone.'" name="phone_number" />'; }
and then , i call in a new object grocery_CRUD();
implements a callback....
public function user() { $cek = $this->session->userdata('logged_in'); if(empty($cek)) { header('location:'.base_url().'login'); } else { $crud = new grocery_CRUD(); $crud->set_theme('datatables'); $crud->set_table('tb_user'); $crud->set_subject('User'); //This Callback User ID $crud->callback_before_insert('user_id',array($this,'get_user_id')); $crud->callback_field('user_id',array($this,'get_user_id'));
//This Callback Phone Number Field $crud->callback_field('phone',array($this,'callback_phone'));
$crud->callback_before_insert('phone_number',array($this,'callback_phone')); $output = $crud->render(); $this->_admin($output); } }
regards..!! :D