I'm trying to generate a ticket id value with this format: yymm######
to be used in my database table. This expresses a 2-digit year, 2-digit month, and a 6-digit numeric id that is unique to the year-month prefix.
If there are no other tickets id's for the current month and year (April of 2017 at time of posting), the the numeric portion of the value should be default to 000000
. The correct generated ticket id, in this case, should be: 1704000000
.
If there are 1 or more pre-existing ticket id's in the current month - year, then the new ticket id should be 1 more than the highest ticket id.
I am currently using php to increment the ticket id like this:
$tkid = $rowt["TICKET_ID"] + 1;
But using this code, generates a ticket id like this: 17041
I have already put my ticket_id
attributes to unsigned zerofill
and type int 6
.
Due to a design reason, I do not want to use auto increment.
Code:
$sqlt = "SELECT TICKET_ID FROM group where groupid = '$tid' ";
$ticket = mysqli_query($conn , $sqlt);
$rowcount = mysqli_num_rows($ticket);
if ($rowcount == 0)
echo "No records found";
else
{
$rowt = mysqli_fetch_assoc($ticket);
}
$tkid = $rowt["TICKET_ID"] + 1;
<input type="text" readonly="readonly" value="<?php echo date('ym'). $tkid ;?>" name="TICKET_ID" >