1
I would like to know how to insert the following combination, via PHP or mysql:
I have a field called YEAR that needs to receive the current YEAR 2017 format, via php or mysql.
I have a code field that will need to receive the concatenation of the protocol number + the year, but this protocol would be the table ID field that is generated automatically with AI.
How would you get this ID, even if you hadn’t generated any fields yet, because it is auto_increment.
In short, when making a new registration, he would take the ID + year and put inside the field CODE.
The code field is auto_increment?
– novic
No, only the ID is A_I, the code will receive the current ID + year
– Rafael Meirim
If you have to do two processes! first enter the record, take the Id and update the Code field with year and id! if there’s any code we can base on?
– novic
i used an Random to generate this code, but it gets very random, public Function gera_codigo(){ Return substr(time().Rand(10000,99999),-15); }
– Rafael Meirim
The code field is to sweep the base?
– novic
That, code field is varchar
– Rafael Meirim
then if it generated id 1 it would be 12017 if it were id 2 it would be 22017 so on?
– novic
That’s right, when the year changes it becomes 12018, because they are two primary keys, ID and YEAR, and if the year changes the ID becomes 1 again
– Rafael Meirim