princeofpersia Posted November 26, 2010 Share Posted November 26, 2010 Hi Guys I have a code what inserts very simple queries to database, im trying to add a random reference number for each enrty using $reference = rand(111111111111,999999999999); but each time I add an entry it gives me the same random number previously generated for previous entry can you help pleasE? Quote Link to comment Share on other sites More sharing options...
MrXHellboy Posted November 26, 2010 Share Posted November 26, 2010 Try: mt_srand((double)microtime()*1000000); $reference = mt_rand(111111111111,999999999999); Quote Link to comment Share on other sites More sharing options...
waterssaz Posted November 26, 2010 Share Posted November 26, 2010 If you say you are putting multiple entries into the database, I presume you are using some kind of loop, if so is $reference set inside or out of the loop? :-) Quote Link to comment Share on other sites More sharing options...
princeofpersia Posted November 26, 2010 Author Share Posted November 26, 2010 yeah, i have solved it, I have changed the number from $reference = rand(111111111111,999999999999); to $reference = rand(11111111,99999999); so less digits and it work fine, im not using loop but I have tried it few times and now it gives me different reference numbers each I add an entry, thanks for you time guys Quote Link to comment 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.