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.