How to insert the last id from a table into another table in MySQL?
- by James
I want to take the id of the most recent item in a database, increment it by one and insert that new id in to another table.
I tried:
$select = mysql_query("SELECT id FROM tableName ORDER BY id DESC");
while ($return = mysql_fetch_assoc($select)) {
$id = $return['id'];
$newId = $id++;
}
mysql_query("INSERT INTO anotherTable (someColumn) VALUES ('$newId')");
But it didn't work. How can this be done?