Вы можете сначала получить последний urnno
, сохраненный в table
, получить его числовую часть, увеличить его, а затем сохранить его в table
.
Я написал возможное решение вашей проблемы, комментарии упоминаются везде, где это необходимо. Посмотри, поможет ли это тебе.
public function myfuntion() {
if($_POST){
// get the last row saved in table
$last = $this->db->select('urnno')->from('student')->order_by('id', 'DESC')->get()->row(); // id or some other auto incremented field
// get urnno from the last row
$last_urnno = $last->urnno;
$last_arr = explode("-", $last_urnno); // make it an array to get the numerical part
$new = $last_arr[1] + 1; // increment the value
$urnno = "NU-{$new}"; // new value
$data = array(
"name" => $this->input->post(''),
"email" => $this->input->post(''),
"phone" => $this->input->post(''),
"urnno" => $urnno // new value
);
$sql = $this->db->insert('student', $data);
if($sql){
echo "success";
}else{
echo "fail";
}
}
$this->loca->view('myform');
}