bobrandolf1 Posted November 5, 2008 Share Posted November 5, 2008 Hi guys, I have searched the forum but can't find the answer... I am sure its very simple. All I want is to generate a new Unique ID on each line, I need 200. I can then copy and paste them. So far I have, <? $uniqueid = md5(uniqid(rand(), true)); echo "$uniqueid<br>"; ?> How would I get this script to repeat itself on a new line, do you have to make PHP count? Thanks in advance! Bob in London Quote Link to comment https://forums.phpfreaks.com/topic/131484-help-for-newby/ Share on other sites More sharing options...
bobbinsbro Posted November 5, 2008 Share Posted November 5, 2008 if this is for a database table, there are other and better ways to do this. if this is for html output, and you want 200 just loop the code you have 200 times: for($i = 0; $i < 200; ++$i){ $uniqueid = md5(uniqid(rand(), true)); //i would change uniqid(rand(), true)) to time(), since that will give you a unique md5 as well, but will call less functions. echo "$uniqueid<br>"; } Quote Link to comment https://forums.phpfreaks.com/topic/131484-help-for-newby/#findComment-682834 Share on other sites More sharing options...
Adam Posted November 5, 2008 Share Posted November 5, 2008 for ($i = 0; $i <= 200; $i++) { echo rand(10000, 99999) . '<br />'; } Would print 200 unique 5 digit numbers.. Quote Link to comment https://forums.phpfreaks.com/topic/131484-help-for-newby/#findComment-682838 Share on other sites More sharing options...
JasonLewis Posted November 5, 2008 Share Posted November 5, 2008 for ($i = 0; $i <= 200; $i++) { echo rand(10000, 99999) . '<br />'; } Would print 200 unique 5 digit numbers.. No it wouldn't. It would print 201 random 5 digit numbers. Who's to say the same number doesn't appear twice? If you were to do it that way, you'd have to add the numbers to an array then check the array to see if the new generated number isn't already present. Quote Link to comment https://forums.phpfreaks.com/topic/131484-help-for-newby/#findComment-682841 Share on other sites More sharing options...
bobrandolf1 Posted November 5, 2008 Author Share Posted November 5, 2008 you guys are amazing that was lightning quick. thanks so much! bob Quote Link to comment https://forums.phpfreaks.com/topic/131484-help-for-newby/#findComment-682844 Share on other sites More sharing options...
Adam Posted November 5, 2008 Share Posted November 5, 2008 Hah oh yeah! put it down to negligence.. Quote Link to comment https://forums.phpfreaks.com/topic/131484-help-for-newby/#findComment-682916 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.