Consecutive number between two values

0

Is there a function in php to generate consecutive numbers like rand (1,100); but that they are consecutive?

I need to be able to give you the start number and the final number.

Or maybe it can be done directly in mysql ... I explain what I want to do the same thing I'm using too many steps.

I have a table of codes ean-13 in mysql where I keep the fixed numbers of the ean and the variables the variables are two fields in mysql the first code number that I have and the last one. The tables are: Country | Code | initial value | final value that would equal 84 | 36562 | 00001 | 99999 The first two are fixed and the final two are the range of codes that I have purchased.

On the other hand I have another table where I assign those codes to a specific article checking that it is not already assigned and assigning the first one that is free.

The initial idea was to generate an array with all the codes that I have bought, Make a query to check that they are not assigned to an article and assign them in an insert. But the same thing I can do everything in the same query.

Is it possible to hit? if you can not, is there a rand function (1,100) for php but being consecutive?

I've tried this:

        $CCodEan = Consulta_Dinamica("Simple","*","Configuraciones","'que' = 'Codigos' AND '1' = '".$_SESSION['Empresa_Pais']."' ");

        $CeanLibre = "SELECT min(3) + 1 as prox_ean_libre FROM (SELECT 0 AS 3 union all SELECT 3 FROM Direcciones&Codigos WHERE 3 >= '".$CCodEan[2].$CCodEan[3].$CCodEan[4]."' AND 3 <= '".$CCodEan[2].$CCodEan[3].$CCodEan[5]."' ) t1 WHERE not exists (select null FROM Direcciones&Codigos t2 WHERE t2.3 = t1.3 + 1 AND t2.3 >= '".$CCodEan[2].$CCodEan[3].$CCodEan[4]."' AND t2.3 <= '".$CCodEan[2].$CCodEan[3].$CCodEan[5]."' )"; //miramos de nuevo el ultimo codigo por si aca
        $REanLibre = mysqli_query($Conectar ,$CeanLibre); //pongo un resultado de la consulta

        $DEanLibre=mysqli_fetch_array($REanLibre); 
        $EanLibre = trim($DEanLibre["prox_ean_libre"]);

echo $EanLibre;

but I get an error.

In this case 3 is the field where I keep the ean codes for the articles and $CCodEan[2].$CCodEan[3].$CCodEan[4] would be the first code ean complete (in the absence of the control digit) and $CCodEan[2].$CCodEan[3].$CCodEan[5] would be the last code I have (also without the check digit).

A thousand thanks for your help

    
asked by Killpe 15.02.2017 в 20:04
source

1 answer

1

Your question includes several questions in itself. I replay you in reference to a function that returns you in an array all the values between 2 numbers.

function resultado($numero_inicial, $numero_final){
    for ($i=$numero_inicial;$i<$numero_final;$i++){
        $numeros[] = $i;
    }
    return $numeros;
}

How to invoke this function?

resultado(10, 100);
resultado(1000, 50000);
    
answered by 15.02.2017 в 20:43