Zkuste to pomocí str_pad()
Po vložení získejte ID posledního vložení .pass s funkcí generování, jako je tento parametr
generate(prefix,last_insert_id);
Příklad: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'
}