Talisman57 Posted July 18, 2012 Report Share Posted July 18, 2012 Hello, I'm trying to make it so that random ID's are assigned to pilots, and not in sequential order. Is there a possibility to this? I've done it for other CMS's but I don't know if the MySQL wont like the randomness. Thanks for your help Dave Quote Link to comment Share on other sites More sharing options...
Moderators mark1million Posted July 18, 2012 Moderators Report Share Posted July 18, 2012 Pilot id's are generated in sequence, if you mess with this things could get messy and confusing. Quote Link to comment Share on other sites More sharing options...
Tom Posted July 18, 2012 Report Share Posted July 18, 2012 Providing they're unique you should be ok to insert them rather than using mysqls automatic generation. I don't have time to go check what you need to do right now but you'll need to edit the function that processes registration. You'll want to retrieve all existing pilot codes from the database and add a while loop to generate a new one and check it doesn't already exist. Then you'll also need to change the sql insert to define a pilot code. Quote Link to comment Share on other sites More sharing options...
Talisman57 Posted July 18, 2012 Author Report Share Posted July 18, 2012 Tom, That's what I was looking into. Thought I would need a while loop. I'll try it out and see. Thanks Quote Link to comment Share on other sites More sharing options...
Tom Posted July 18, 2012 Report Share Posted July 18, 2012 Excluding the phpVMS parts you could do something like this: // get all pilotcodes into array (probably need your own function for this) $rand = rand(100,999); while(in_array($rand, $allpilotcodes)){ $rand = rand(100,999); } // Put $rand in as your new pilotcode Quote Link to comment Share on other sites More sharing options...
Talisman57 Posted July 18, 2012 Author Report Share Posted July 18, 2012 Thanks. I'll try it out, and let you know 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.