I use the function to create a unique identifier using the last identifier from the table. But the problem arises when a person opens at about the same time. Could you suggest any fix in the current function? Since this function is used in production and on a live server, a small code adjustment will be much better.
Here is a function using:
function approvalNumber() { $data=array(); $text = "APN/"; $position = "front"; $this->db->order_by('approval_id','desc'); $this->db->limit('1','0'); $query=$this->db->get('approval_note'); if($query->num_rows()>0) { foreach($query->result_array() as $row){ $data[] = $row; } } $query->free_result(); if(count($data)) $id=str_pad((int) $data['0']['approval_id']+1,4,"0",STR_PAD_LEFT); else $id='0001'; return $approvalNo = $text.$id; }
This will be genrate: APN / 0371
source share