I’m trying to retrieve the id of one table A to insert into another table B. I cannot use last_insert_id() as i have not inserted anything into A. Any ideas on how to do this nicely?
$n = mysql_query("SELECT max(id) FROM tablename"); doesn’t seem to work, nor does
$n = mysql_query("SELECT max(id) FROM tablename GROUP BY id");
In MySQL, this does return the highest value from the
idcolumn:However, this does not put that id into
$n:To get the value, you need to do this:
If you want to get the last insert ID from A, and insert it into B, you can do it with one command: