Refference number using PHP
look at the rand(); function http://uk3.php.net/rand or unique id http://fr.php.net/manual/en/function.uniqid.php Or you can create your own function if you want to use letters with numbers.
DarkMantis wrote: How would I make a unique refference number in PHP? Explain what you mean by "unique reference number", and we'll know which "right" answer to give you.
yours31f wrote: wow, nice come back spy, run out of jokes for the day? Of course not… every one of your posts is a joke. Almost a crime to humanity.
DarkMantis wrote: I mean something like on a form after you fill it out it gives you a refference number incase you need to contact them and they can reffer it to the reference number that you give them. If you know what i mean?
Yeah, you could use rand(). I would say to make a random string generator function and then md5 the random string you gave them, store it in a database and output it. That way you are pretty sure it is unique since you can check if it is already in the db. (even though this isn't a number)
DarkMantis wrote: I mean something like on a form after you fill it out it gives you a refference number incase you need to contact them and they can reffer it to the reference number that you give them. If you know what i mean?
Ahh, okay. Instead of just generating a random item with rand or uniqid, why not just use unique aspects of the form itself to MD5 and give (truncated to a length of your choice, of course) as a reference code? Examples of this could be the username, a person's mailing address, or even a person's last name and birthdate. As everyone else has already stated, you'd need to store the ref number in the db in order for it to be referenced later.
If the information is going to be stored in the database why not have a unique table index? That would actually speed-up look up of the form and guarantee uniqueness - whereas random strings and integers do not.
Just have a column - in the row where you store the information - represent the row index. Set it to auto increment and be the primary key for the table.