[UPHPU] Dual ID numbers

TJ Hunter tjhunter at gmail.com
Tue Jun 7 10:31:38 MDT 2005

On 6/7/05, Timothy Humphrey <timothy.humphrey at gmail.com> wrote:
> Hello all.
> I need to be able to store info into a MySQL DB using auto-increment.
> Simple enough. But I need to have individual auto-increments based off a
> multiple digit ID number.
> Let me give an example: I have a music collection of three composers. I
> want to personally assign an ID number to each composer (1, 2, 3). Then
> I want to enter the info for each CD (with a drop-down list to choose
> the composer #1, 2, or 3), and have a MySQL auto-increment number
> assigned for each CD. The problem is that I want to have CD 1-20 for
> Composer 1, CD 1-20 for Composer 2, and CD 1-20 for Composer 3.
> Should I create 3 DB tables, one for each composer? or should I use PHP
> to assign the numbers and leave MySQL with "int" fields? or is there a
> way to use a primary and secondary field within the auto-increment
> feature of MySQL?
> I would prefer to use the last option, because then I could have a
> million composers without adjusting the PHP each time. And I prefer not
> to use the second option (PHP assigned numbers) because if I have a
> hundred people entering my data (what can I say, it's a vast
> collection), then I don't run the risk of two people entering the same
> number.
> Timothy

As far as I know, MySQL doesn't support what you're trying to do.
Here's what I would do though, let MySQL auto increment your primary
key as normal and use that key for relationships, then create another
field for your special id. you'll have to write your own php code to
figure out what the next id is going to be instead of relying on the
user to type it in or MySQL generating it for you.


More information about the UPHPU mailing list