views:

20

answers:

1

Ok, I find myself doing this often. I'll attach ids to my tables and I'll "link" the tables together. Just a simple example, a team roster might have categories. Each category has an id. When I add players into the roster, I'll assign them a category id as well to signify that they are part of that category.

My question is, for this example, say I'm creating a category and a player at the same. I submit the category but now I have to get the category id to assign it to the player table row. Any suggestions on how to do this efficiently? Currently I would query the database again, and search for specific data related to the category, which doesn't seem very effective.

Note also, the id's Im using are generated by mysql.

Any suggestions would be helpful!

+3  A: 

Check out mysql_insert_id()

Alec
awesome! Thank you!
Dalton Conley