algorithm - Generate unique 12 letter alphanumeric string from two primary keys of table in php -


i have 2 tables: category(cat_id type int,cat_name) , books(book_id type int,cat_id). when assign book user book code. want form book code containing 12 alphanumeric characters , must originated cat_id , book_id. should able decode code cat_id , book_id. idea?.

ok here go...

this can handle max signed integer types. , produces no more 12 characters.

$firstid = "2147483646"; $secondid = "2147483646"; $firstbinary  = str_pad(base_convert($firstid, 10, 2), 31, "0", str_pad_left); $secondbinary  = str_pad(base_convert($secondid, 10, 2), 31, "0", str_pad_left); $finalbase36 = str_pad(base_convert($firstbinary.$secondbinary, 2, 36), 12, "0", str_pad_left); var_dump($finalbase36); 

update: sorry made mistake.. should trik updated code.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -