I have the following code where I get the MAX
of a code, but this code is a String
. To this MAX
I separate it in two to get the first 3 initials that are letters and in the numbers to add 1 to the numbers.
$query = "SELECT MAX(CodMaquina) FROM Maestro_Maquinas WHERE Centro_Costo = '$centro_costo'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_row($result);
$numbers = preg_replace('/[^0-9]/', '', $row[0]);
$letters = preg_replace('/[^a-zA-Z]/', '', $row[0]);
$sumnumbers = $numbers+1;
$codmaquina = $letters.$sumnumbers;
echo $codmaquina;
The initial value of row[0]
is ELA0045
but the result is ELA46
. How can I keep the 00
or apply another formula to add.