Umair Iftikhar Umair Iftikhar - 4 months ago 6x
PHP Question

unique ids are not in sequence in PHP

I want to make a database primary key. I am using PHP uniqid() Function.


Basically I want to add Student IDs in student table of database

e.g PHP-16-001

In which PHP is 3 character Course ID , 16 is year and 001 is student ID.

I can Add this via "."

$id = "php"."date('Y')".$i;

in which $i is a variable who is incrementing but when I fetch data from database I got


How can I got all characters?


String concatenation operator in php is '.', so to get your extra '-' characters add them to you string, Check the below code. You should insert your unique id in database as "php-16-001". Make sure your $i variable is a string.

$id = "php-" . date('y-') . $i;