|
-
Jul 21st, 2007, 04:41 AM
#1
Thread Starter
Member
Generating a random 10 digit number
Mornin all, I have what should be an easy q today...
I have a form that a user fills out and when they hit submit, it does a number of things, one, it checks to see if the email address supplied is already in the db (in which case it kicks back an error n halts), otherwise, it comes back with a visual confirmation showing all data and loads the information into the db as a new record.
What I'm trying to do is to have it so that a unique, 10 digit number is autogenerated and attached to the same record that's returned and also loaded to the db with that same record. A serial number would be a fair description.
Any ideas?
-
Jul 21st, 2007, 06:27 AM
#2
Re: Generating a random 10 digit number
Which part are you stuck with? Generating the number, or storing it in the database?
-
Jul 22nd, 2007, 02:34 PM
#3
Re: Generating a random 10 digit number
well there are a few ways at doing that.
1. One large rand():
PHP Code:
$serial = rand(1111111111, 9999999999);
That will make a random 10 digit string.
2. You can have several rand()'s and make it more random:
PHP Code:
$serial = rand(111, 999) . rand(111,999) . rand(11, 99) . rand(11, 99);
My usual boring signature: Something
-
Aug 3rd, 2007, 02:57 AM
#4
Hyperactive Member
Re: Generating a random 10 digit number
dclamp sollution is very nice but you still didn't answer if you have problem only with the random number or when storing it in database!
Also there are 2 other sollutions:
1)
srand((double)microtime()*1000000);
echo rand(1000000000,9000000000);
2)
$value_s = mktime(0,0,0,date('d'),date('m'),date('Y'));
echo $value_s;
-
Aug 20th, 2007, 08:48 AM
#5
Addicted Member
Re: Generating a random 10 digit number
Yep. Try to use rand(); function.
PHP Code:
$whatever = rand(1000000000, 9999999999);
If you want a random 10-Digit string then:
PHP Code:
$token = substr(md5(rand(1000000000, 9999999999)), 0, 10);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|