I need to generate key codes for users so i need that to be unique in db.
I need to repeat this cycle until key is unique:
create key;
if($key is not in db){
insert key;
}else{
repeat control with new key;
}
i thought about while() but can’t understand how to implement that.
Other method to insert db unique keys and update db unique key could be written in sql queries directly instead of using php script? (INSERT/UPDATE UNIQUE KEYS with Sql Query)
hoping is clear the question.
Explanation:
You first create a unique key using the custom function
create_uniuqe_key, so nowwe have a starting value for
$key.Second , we have a
whileloop , please remember:as long the expression return true we will get into the loop.
So , as long as our custom function
this_key_exists(which return true or false) returns true (which means – the key is not that uniuqe – exists in the database) we will create a new unique key and check it again and again.