I\'ve created a column on my form named trackingcode
and it increments every time you insert a new data.
Now I thought about adding a prefix and then the nu
Try with str_pad()
After insert get last insert id.pass with generate function like this param
generate(prefix,last_insert_id);
Ex:generate("REC",1);//REC0001
function generate ($value='',$inp=""){
return $value.str_pad($inp,4, "0", STR_PAD_LEFT);
}
//Insert query
$query = 'INSERT INTO request(req_date, reqname, date, empname, position, account, platform, processor, ram, monitor, phone, phonetype, headset, req_table, req_chair, approval, status) VALUES("'.$req_date_clean.'", "'.$reqname_clean.'", "'.$date_clean.'", "'.$empname_clean.'", "'.$position_clean.'", "'.$account_clean.'", "'.$platform_clean.'", "'.$processor_clean.'", "'.$ram_clean.'", "'.$monitor_clean.'", "'.$phone_clean.'", "'.$phonetype_clean.'", "'.$headset_clean.'", "'.$req_table_clean.'", "'.$req_chair_clean.'", "'.$approval_clean.'", "'.$status_clean.'"); ';
if(mysqli_query($connect,$query)){
$last_id = mysqli_insert_id($connect);
$code = generate("REQ",$last_id);
mysqli_query($connect,"update request set trackingcode='$code' where reqnumber='$last_id'");
//exec code : update tablename set trackingcode='$code' where tableprimary_id='$last_id'
}