Quote:
Originally Posted by TudvariHUN
Yes,the auto increment would be very easy to use,but it wouldn't be realistic.
|
You could write a simple query that generates a random number that isn't in the database yet. Note that, because 5 digits will only run from 00000 to 99999 that
this is not a good solution when you have a lot of users. I'd say after 5-10K users you will need to rethink this tactic and move to 6 or 7 digit numbers.
The query could be:
PHP код:
SELECT FLOOR(RAND() * 99999) AS random_generated_number
FROM my_table
WHERE random_generated_number NOT IN (
SELECT phone_number
FROM my_table
)
LIMIT 1
What this does is, it will return a set of randomly generated numbers (between 0 and 99999 because RAND() returns a double from 0 to 1) that are not already in my_table. LIMIT 1 means it will limit the set to the first occurence.
More here:
http://stackoverflow.com/questions/4...ber-generation