I would like to know if there is any way to know the first free mysql record, but not the last, if not the first free that exists.
Ex:
I have a busy record 1,2,3,6,7,8,9 the first free would be 5
At the moment I have a code that tells me the last thing that would be this:
$CIdmaxFact = "SELECT MAX(CAST(codfactura AS UNSIGNED)) AS ultimocod FROM Facturas WHERE empresa='".$_SESSION['Empresa_Id']."' AND serie='".$_POST["Infactura_serie"]."' "; //miramos de nuevo el ultimo codigo por si aca
$RIdmaxFact = mysqli_query($Conectar ,$CIdmaxFact); //pongo un resultado de la consulta
$DIdmaxFact=mysqli_fetch_array($RIdmaxFact); $idmaxFact = trim($DIdmaxFact["ultimocod"]); $idmaxFact ++;
$idmaxFact = str_pad($idmaxFact, 4, "0", STR_PAD_LEFT);
But it does not help me at all, since only the last one tells me. Any ideas?