Here is what I use to get a number. What you do with it is up to you.
<CFSET DIFF = 'NO'>
<CFLOOP CONDITION="DIFF EQ 'NO'">
<CFSET IDNUMBER= #RANDRANGE(10000, 10000000)#>
<CFQUERY NAME="ID" DATASOURCE="SURGWEB">
SELECT IDNUMBER
FROM tblres_books
WHERE IDNUMBER = #IDNUMBER#
</CFQUERY>
<CFIF #ID.RECORDCOUNT# IS 0>
<CFSET DIFF = 'Yes'>
</CFIF>
</CFLOOP>
>>> [EMAIL PROTECTED] 08/25/01 07:44PM >>>
Here is a little trick I did, I come up with a random id, then I make sure
that the field that is using this random id can not have duplicates in it,
then I have a loop that has something about do while error neq true which is
set before the loop, then I have a query that inserts the id into the
database and I cftry and cfcatch any errors it finds (which would mean I
tried to input a duplicate id) and if it finds one it creates another random
id and set error = true so the loop will take it over again until it is
finally unique. HTH
Bob Everland
-----Original Message-----
From: Chris Badouin
To: CF-Talk
Sent: 8/25/01 6:20 PM
Subject: Random Checking
All-
Quick question....
generating a random number and adding that number to a particular form
field
to create a username. I wish to check the users table to make sure that
no
matching values exist, and if they do loop back and do it again...
Though my loop does not seem to work properly....
I know I am missing something stupid, but does anyone have a sample of
this
I could see?
CB
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists