TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-17-2008, 02:51 PM   #1 (permalink)
The Contributor
 
Join Date: Sep 2008
Posts: 39
Thanks: 9
code_junkie is on a distinguished road
Help 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?
__________________
Trying to learn all I can about PHP. Teach me what you know...
code_junkie is offline  
Reply With Quote
Old 12-17-2008, 03:58 PM   #2 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Put the id on auto_increment, then it'd be a larger and larger number. So it'll always be unique.
__________________
Tanax is offline  
Reply With Quote
Old 12-17-2008, 04:01 PM   #3 (permalink)
The Contributor
 
Join Date: Sep 2008
Posts: 39
Thanks: 9
code_junkie is on a distinguished road
Default

The number also has to be displayed on the screen for the user.
__________________
Trying to learn all I can about PHP. Teach me what you know...
code_junkie is offline  
Reply With Quote
Old 12-17-2008, 04:02 PM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

After insert, just fetch the number and display it then!
__________________
Tanax is offline  
Reply With Quote
Old 12-21-2008, 12:01 AM   #5 (permalink)
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default

@code_junkie

A tip would be

mysql_insert_id():

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

:)
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.
EyeDentify is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Showing random links with an array paulOr Advanced PHP Programming 6 10-24-2008 09:28 AM
What do you use for random integers? Enfernikus Absolute Beginners 6 06-09-2008 08:46 PM
how to get the rows affected(not number of rows) kororo203 Absolute Beginners 2 04-23-2008 08:32 AM
Version Checker khile Advanced PHP Programming 21 03-04-2008 10:08 PM
How Rdoanm is Rondam? Wildhoney General 3 09-19-2007 01:32 PM


All times are GMT. The time now is 01:44 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design