I have an old registration system, and a new one. (two tables).
The old system holds an old category, and the new one holds some new categories that couldn't be implemented into the old system just yet.
So moving everything to one of the systems is not an option at the moment.
My problem:
I need to connect the two tables so the ID's operate as "auto increment" and will follow each other somehow.
Here is a scenario:
// table#1 = old system (car)
// table#2 = new system (tractor, truck, marine)
A new car is registered in table#1 and gets the ID : 13579,
then some other vehicle is registered in table#2 and should get the ID : 13580,
and when a new car is registered in table#1 again, it should get ID : 13581.
and so on...
In my mind it goes something like this:
Right before adding the new vehicle into one of the tables, always do a lookup in the other table and check which one is the last/highest ID and do +1 before setting the new ID...
UPDATE 20120614:
Here is one solution I came up with:
$qry_tbl1 = mysql_query('SELECT MAX(id) AS tbl1_max_id FROM tbl1');
$get_tbl1 = mysql_fetch_assoc($qry_tbl1); extract($get_tbl1);
$qry_tbl2 = mysql_query('SELECT MAX(id) AS tbl2_max_id FROM tbl2');
$get_tbl2 = mysql_fetch_assoc($qry_tbl2); extract($get_tbl2);
$new_max_id = max(array($tbl1_max_id,$tbl2_max_id)) + 1;
This is not a good solution, but the only one I got to work.
Immediately after the user hits the submit button, I do this and the INSERT a new record.
Then, further down the script, based on $new_max_id
i update that record with additional data...
Is this an acceptable solution?