Pages

Subscribe:

Ads 468x60px

Labels

2014年10月24日 星期五

PHP Generate Unique Order Number with Date


I want to generate unique identificator in following 12 numeric format:
YYYYMMDDXXXX
Example:
201403052318
Where:
YYYYMMDD is a current date value and other XXXX is randomly generated value.
$today = date("Ymd");
$rand = sprintf("%04d", rand(0,9999));
$unique = $today . $rand;
Daily required unique volume is about 100. What methods using PHP should I use to prevent possible duplicates in rand values or make all id maximum unique? Maybe possible use current time functions to compact these numbers in last 4 characters?
EDITED: Unique value connected to MySQL database as prime index of table. It is initial values not connected to any stored information in database.

沒有留言:

張貼留言