Random and unique number generation process in php -
please check below example better explanation.
in form have below fields
example :
account creation count : 300 account prefix : 123 (value depend on user) account length : 4 (value depend on user)
here length of account prefix 3 , account length 4 4-3 =1
here 1 if create random characters between 0-9 =10 , a-z =26 total 36 user can create maximum 36 accounts prefix.
but want check in database number prefix , random number
like random single digit "d" execute query like
select id table length(number) =4 , number '123d'
if exist in database need create random character.
i using below function going infinite loop.
code :
function find_uniq_rendno_accno($length = '1', $field = '', $tablename = '',$prefix) { $key = ''; $keys = array_merge(range(0, 9), range('a', 'z')); ($i = 0; $i < $length; $i++) { $key .= $keys[array_rand($keys)]; } $where = array($field => $default.$string); $acc_result = $this->ci->db_model->getselect('count(id) count', $tablename, $where); while ($acc_result[0]['count'] != 0) { $key= $this->find_uniq_rendno_accno($length, $field, $tablename,$default); } return $key; } please me out problem.
thanks in advance.
Comments
Post a Comment