Any Ideas?
| From: | Matthew Oatham | Date: | Mon, 22 Mar 2004 23:51:49 +0000 |
| Subject: | Any Ideas? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-181188@lists.php.net to get a copy of this message | ||
Hi,
Sorry to ask this question, I am fairly new to PHP and wanted to ask for some help with the
following.
I have a MySQL table which uses a auto_increment int as the primary key - when I do an insert I want
to create another id based on the primary key and insert this into the same table i.e. if I do an
insert and the primary key is 3 I want to generate the ID CR-003, if the primary key was 34 I would
want to generate the id CR-034. So I guess I need to know the following.
are there any functions that retrieve the last primary key created in the MySQL table?
are there any math functions that will turn 1 into 001 or 34 into 034 or keep 213 as 213 etc...
what would be the best implementation i.e. do an insert, get the primary key then do an update or
lock the table use a function to get the next availible primary key generate the additional key and
then do 1 insert? Guess this implementation depends on how / if I can lock the MySQL table.
Sorry its a long one!
Cheers
Matt