[kwlug-disc] Hash functions.
kb at 2bits.com
Sun Jan 2 13:45:38 EST 2011
You just need to generate a quasi-unique number from a set of variables.
$ php -a
php > $string = "Something or other with date and time";
php > $hash = md5($string);
php > print $hash;
Stuff what you want in $string, be it the store, date, whatever.
Then you can use the $hash value as the key in the database to track
All this would have worked if you have not said it should be short.
But you want it to be short, so the above may be too long.
Would this work? It is based on the microsecond time. If you
have a transaction every few seconds, then it should be OK.
Clashes can happen if you have two at the same exact micro-
$ php -a
php > print uniqid();
Another approach: why not use an autoincrement key in the database table
that is the primary key for the coupon table, and be done with it? The
rest of the data can be cross indexed in that table (store ID, date,
time, description, ...etc.). It will be just a number.
Khalid M. Baheyeldin
Drupal optimization, development, customization and consulting.
Simplicity is prerequisite for reliability. -- Edsger W.Dijkstra
Simplicity is the ultimate sophistication. -- Leonardo da Vinci
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the kwlug-disc_kwlug.org