Page 1 of 1

Unqiue ID columns - PHP or MySQL query?

Posted: Mon Feb 26, 2007 5:27 pm
by mjseaden
Hi,

I have several tables - e.g. Products, Manufacturers, that has a unique ID associated with each row - e.g. ProductID, ManufacturerID.

When I delete rows in the middle of the table, I want to reassign the IDs into numerical order.

Also, when I insert a row at the end, I want to know the last ID in the table without having to read the whole table.

How do I carry out both operations, and should this be carried out via a MySQL query, or via PHP?

Many thanks

Posted: Mon Feb 26, 2007 6:25 pm
by mikeq
dont reassign the IDs, if you have used them as foreign keys then you would need to update all those records also. Dont do it.

To get the last generate ID use

mysql_insert_id() funtion

http://www.php.net/manual/en/function.m ... ert-id.php