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