TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Unique random number? (http://www.talkphp.com/advanced-php-programming/3779-unique-random-number.html)

code_junkie 12-17-2008 02:51 PM

Unique random number?
 
I have a site for my company that requires a report number. This report number is the id for a specific report, so must be unique. At first I assumed that just a randomly generated number would work, but didn't think the site would get as many reports as it is. So now I need to set it so the random number is unique. How can I do this? My first thought is to query the db to see if the number exist then somehow get a new number if it does exist, but that seems like the wrong way to me. Can someone help me?

Tanax 12-17-2008 03:58 PM

Put the id on auto_increment, then it'd be a larger and larger number. So it'll always be unique.

code_junkie 12-17-2008 04:01 PM

The number also has to be displayed on the screen for the user.

Tanax 12-17-2008 04:02 PM

After insert, just fetch the number and display it then!

EyeDentify 12-21-2008 12:01 AM

@code_junkie

A tip would be

mysql_insert_id():

http://se2.php.net/manual/en/functio...-insert-id.php

:)


All times are GMT. The time now is 05:12 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0