CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 unique Registration code

Print topic Send  topic

Author Message
will

Posts: 88
Posted: 10/09/2008, 10:23 PM

Hello fellow ccser's I am having trouble trying to figure out the best and cleanest way and how to get this function to work in ccs 4

I want a hidden field on a registration page and I want it to generate a unique code for accounts

i need it in this format

AS094437-01

i always need the AS to be infront and everytime a account is created this needs to be unique.
View profile  Send private message
datadoit
Posted: 10/11/2008, 12:19 PM

Here's a longwinded idea:

$num =
"AS".rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9)."-".rand(0,9).rand(0,9);
jjrjr1


Posts: 942
Posted: 10/11/2008, 2:21 PM

Hi.

Great idea data..

I have this post also that might help regarding true random numbers.

Let me know what you think.

http://ccselite.com/forums_topics_view.php?forum_id=8&forum_topic_id=10

Have fun


_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
ReneS

Posts: 225
Posted: 10/11/2008, 2:41 PM

Hi,

Depending on how many accounts you have/want, because you will run out of uniqueness with the format you have right now. I think...


Rene
View profile  Send private message
jjrjr1


Posts: 942
Posted: 10/11/2008, 2:50 PM

Hi Rene

Check out this link for truly random numbers.

http://ccselite.com/forums_topics_view.php?forum_id=8&forum_topic_id=10

Let me know what you think


_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
ReneS

Posts: 225
Posted: 10/12/2008, 12:19 PM

Hi,
Maybe i did not understand the question, is it supposed to be unique or random....


Rene
View profile  Send private message
melvyn


Posts: 333
Posted: 10/14/2008, 8:34 AM

Some advices:
1) Set the field as Unique in your database.
2) Set a catch using a custom insert :
$db = new clsDByourdb();

$sql = "INSERT ".$code......
$db->query($sql)
if($db->next){ //this code was accepted, continue
echo your code;
}else{ // this code was not accepted
echo your code
}

Why? I was using unique codes, as you, a bit shorter in the format DDH-XXXXXX (DD = day, H= morning, afternoon, night) something like TUA-38ASX4 = Tuesday afternoon 38ASX4.
Generating 500 random codes per group, 1,000 per day, I got lots repeated. Around 1 in 3 grups got a code repeated.

so, my third advice is:
3) Use a script to generate bulk codes and see how good they're and if they don't repeat.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com
View profile  Send private message
jjrjr1


Posts: 942
Posted: 10/15/2008, 6:05 AM

Hi

I mispoke in my post above. This code actually makes unique numbers. It guarantees absolutely unique numbers are generated.

http://ccselite.com/forums_topics_view.php?forum_id=8&forum_topic_id=10

Sorry


_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
feha


Posts: 712
Posted: 11/02/2008, 6:45 AM

Hi
Check here
http://www.vision.to/controlled-random-string-password-generator.php

with this function you can random generate whatever you want ...
_________________
Regards
feha

www.vision.to
feedpixel.com
View profile  Send private message
jjrjr1


Posts: 942
Posted: 11/02/2008, 1:39 PM

Feha

Great Code snippet. One would assume that the odds using this code would almost guarantee a unique number.

Thanks

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
dhempy


Posts: 40
Posted: 11/05/2008, 9:40 AM

I agree with Melvyn. You just can't reliably generate unique numbers on the browser side -- doing it server side is fairly trivial. Using an autoincrement primary key in a database table would be my approach, though there are plenty of other ways if that doesn't suit you.

-dave




_________________
David Hempy
Director of Broadcast and Education Technology
Kentucky Educational Television
800-333-9764
View profile  Send private message
jjrjr1


Posts: 942
Posted: 11/05/2008, 11:54 AM

Again

Here is an absolute unique numberf generator in 2 lines of code

http://ccselite.com/forums_topics_view.php?forum_id=8&forum_topic_id=10
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
feha


Posts: 712
Posted: 11/07/2008, 12:55 AM

My function above would produce
$Component->acc_number->SetValue("WEB".VISION_TO_RANDOM(5,0,0,0,1,"")."-".date("my"));
WEB22332-1108
numbers 22332 are random for november 2008
you can make one more check if it exists and call the function again ...
by increasing the length from 5 to 6 .
for some companies is needed more than costumer id 103555033 ...

This can be account number, customer number , support case number, order number etc ...

This is better if you need to export users table and still preserve their accounts ...
hope this helps
_________________
Regards
feha

www.vision.to
feedpixel.com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.