hello all,

i have built an application form that submits info to us. we review that info and then accept or decline.

if we accept...it must insert that users info in the db and genrate a customer number for them

the customer number must be 5 digits in length.

what i need to do is check mysql if that digit exists, if it does, i need to generate a new number...then check again...im having trouble with the flow of this though...not really sure how to do it

is there a built in function for this sort of thing?

thanks in advance 😃

    Not really. MySQL can understand sequences(auto-increment), but random numbers you're have to check for. Best to just make a smal function that does the checking, then start looping through your [man]rand[/man]om number generation.

      so if my ran num is $num = rand(1000, 10000);

      my incrementor would be 10000 and there is a possability i would check the db up to 10000 times for the existance of that number.

      there has to be a more efficient way to do this.

        Maybe set the auto increment number with a starting 5 digit number. The numbers wouldn't be random, but at least you wouldn't have to worry about duplicates.

          that was my next thought 😉

          thanks!!

            Write a Reply...