doddsey_65 Posted April 17, 2010 Share Posted April 17, 2010 How would I assign a random ID to a new user rather than having an AI in the database? Quote Link to comment https://forums.phpfreaks.com/topic/198856-assigning-random-ids/ Share on other sites More sharing options...
leehanken Posted April 17, 2010 Share Posted April 17, 2010 Don't know what an AI is. See http://php.net/manual/en/function.uniqid.php Quote Link to comment https://forums.phpfreaks.com/topic/198856-assigning-random-ids/#findComment-1043867 Share on other sites More sharing options...
ddubs Posted April 17, 2010 Share Posted April 17, 2010 I think he means Auto Increment. The nice thing about auto increment is you have no chance of running into duplicates. A rand() function will have some possibility of generating the same value twice. Quote Link to comment https://forums.phpfreaks.com/topic/198856-assigning-random-ids/#findComment-1043870 Share on other sites More sharing options...
Zane Posted April 17, 2010 Share Posted April 17, 2010 The nice thing about auto increment is you have no chance of running into duplicates. A rand() function will have some possibility of generating the same value twice. QFT.. Why would you want random IDs in the first place? What's wrong with the regular way? But if you did prefer random IDs, the best route would be to propagate about 1000 or so "empty" entries to begin with.. and then run a SELECT RAND() WHERE NOT EMPTY type query...when you create a new user.. Quote Link to comment https://forums.phpfreaks.com/topic/198856-assigning-random-ids/#findComment-1043895 Share on other sites More sharing options...
TeddyKiller Posted April 17, 2010 Share Posted April 17, 2010 $id = rand(1, 9999999); Then use that to insert into database.. Though problem with this.. ID's can be duplicated, which isn't safe. Quote Link to comment https://forums.phpfreaks.com/topic/198856-assigning-random-ids/#findComment-1043898 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.