views:

66

answers:

1

Hi,

I am try to add id from one table to another table to give a relationship to the tables. I am doing this on a number of tables on insert of data from a form. Example: person owns and item so item has item and person ids to link the two, however in some cases I have optional tables so sometimes the ids of those tables will be added to the item table sometimes it will be left null see previous question about this. In my mind doing a select statement to grab ids from other tables then updating the fields that have just been inserted doesn't seem the best way. Anyone got any better ideas on how to do this.

Hope that makes sense.

Thanks.

+1  A: 

You can use the mysql_insert_id() function, which will return the id of the last inserted record.

hookedonwinter