0
I wanted to create an automatic numbering record but reset each year. Getting for example 170001...170002 and for the year 180001...180002
But with this code, I always register 1700001
<?php
function conectarBanco(){
return new mysqli('localhost', 'root', '', 'bvmarco');
}
function primeiraOrdemAno(){
return date('y'). '00001';
}
function novaOrdemServico(){
$db = conectarBanco();
$sql = 'SELECT max(Id) as `ultimo_id` FROM `participacao` WHERE year(data) = year(now()) ';
$result = $db->query($sql);
if($result === true){
$ordem_servico = $result->fetch_assoc();
return ++$ordem_servico['ultimo_id'];
}else{
return primeiraOrdemAno();
}
}
$nova_ordem = novaOrdemServico();
?>
<input type="hidden" name="id" class="form-control" value="<?php echo $nova_ordem ?>" required>
With help I managed to make the code. When you need a tip.
<?php
function conectarBanco(){
return new mysqli('localhost', 'root', '', 'bvmarco');
}
function primeiraOrdemAno(){
return date('y'). '00001';
}
function novaOrdemServico(){
$db = conectarBanco();
$sql = 'SELECT max(Id) as `ultimo_id` FROM `participacao` WHERE year(data) = year(now()) ';
$result = $db->query($sql);
if($result === true){
$ordem_servico = $result->fetch_assoc();
return ++$ordem_servico['ultimo_id'];
}else{
return primeiraOrdemAno();
}
}
$nova_ordem = novaOrdemServico();
?>
170001 is for 2017 and 180001 is for 2018?
– Don't Panic
And if you get to 179999 before you turn the year, what happens?
– Woss
Correct, 17 at the beginning refers to 2017 and 18 refers to 2018
– Adelino Vasconcelos
It would help if you could [Dit] the question pointing out the difficulty found.
– Bacco
wanted it to increase to 1710000
– Adelino Vasconcelos
The record is always the same
– Adelino Vasconcelos
If the question is true, is there any way to describe why you need a value like this? Please answer this by editing the question, not in the comments. Also include the details given in the other comments. Any and all information of the question should be in the question.
– Woss