There is a database where id AUTOINCREMENT. How to make a query in such a way, what would this id, which was, autoincrement pulled out and inserted into another field in the same table? The picture is more understandable. Id field and weight
UPDATE tab SET weight = id WHERE weight= 0
mysql_insert_id() returns 0 if the previous query does not generate an AUTO_INCREMENT value. If you need to save the value for the future, call mysql_insert_id () immediately after the query that generates this value.
INSERT INTO table VALUE (NULL, 0, 0); UPDATE table SET weight = LAST_INSERT_ID() WHERE id = LAST_INSERT_ID();
Do you mean that when adding a new record, immediately register the ID of this record in some field? If so, you can get this ID before requesting an INSERT.
$res_id = mysql_query("SHOW TABLE STATUS LIKE 'table_name';"); $row_id = mysql_fetch_assoc($res_id); $id = $row_id['Auto_increment'];