Gawie Marais wrote:

thanx for the replys guys... basically i need a PHP formula to generate a
'call refenrence code' that is unique to give out to clients whenever they
log a call. this unique 'call reference code should be inserted into a mysql
field within a table.

all i need is a formula to get the last entered code and increment it by
one - the intended code should be forumated by php by using the current date
i.e. 20040101 + a numerical value i.e. 001 for the first 'call reference
code' for the day. when the next call is logged, the next unique available
numerical should be assigned and combined with the date to form the call
reference number.

hope this makes it a bit clearer.

"Pete M" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]

not sure what u want here but
have you looked at the identiry field ??
its called auto_increment in mysql and this gives it record in a
database a unique number

"Insert into table (date_call)values(now() )"

then after the insert do
"select last_insert_id()"


Gawie Marais wrote:

hi all,

i need to create an automatic call reference. i though it would work


the date as ccyymmdd and by adding a '001', '002', etc to the end.

now, i know how to format the date but how would i increment the 001,

002 at

the end... ? i understand that i would have to check back to the

database to

check the last one used. but how... ?

alternatively is to just generate a random number, check it against the
database to see if it's not already used. if not use it. if its used
already, just create another one... ?


do you guys have any laternative suggestions ?



You should really just use an auto_increment field in mysql or a sequence in any other DB. This will let the DB give you a unique ID. If you try to make one yourself, it's possible that you'll have concurrency problems.

paperCrane <Justin Patrin>

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to