There a table in database with name add_sample to store the student sample records. I was storing the inserted information against the auto_increment id but now i want to assign a unique id like 35801 instead of that auto_increment id(e.g 1.) to the first student who entered his/her data. For the second user it should be 35802 and for third it should be 35803 and so on till 99. But when the student number reach to the 100 it should add the 100 to the 3580 to start a new series 36801.
I expect like this:
unique ID | Name | Email | Number_of_Sample | sample_Type
35801 | john | john@gmail.com | 3 | fiber
unique ID | Name | Email | Number_of_Sample | sample_Type
35801 | john | john@gmail.com | 3 | fiber
35802 | sam | sam@gmail.com | 1 | yarn
You could & should continue using the auto-increment
ID but change the value to begin at whatever value you want to start at like so:
ALTER TABLE `add_sample` AUTO_INCREMENT=35800;
You could translate the auto increment id, as present in the database, to your new unique id by using a PHP function.
<?php
function getSpecialSampleId($autoIncrementId)
{
$uptoHunderd = $autoIncrementId % 100;
$aboveHunderd = $autoIncrementId - $uptoHunderd;
return 35800 + 10 * $aboveHunderd + $uptoHunderd;
}
echo getSpecialSampleId(1) . "<br>";
echo getSpecialSampleId(2) . "<br>";
echo getSpecialSampleId(3) . "<br>";
echo getSpecialSampleId(99) . "<br>";
echo getSpecialSampleId(100) . "<br>";
echo getSpecialSampleId(101) . "<br>";
echo getSpecialSampleId(250) . "<br>";
echo getSpecialSampleId(1555) . "<br>";
This will output:
35801
35802
35803
35899
36800
36801
37850
50855
You can use this function to output this special sample id to the outside world, while maintaining the normal auto increment id in your database.