php - How do I connect two rows inserted with unknown id -
i have system accounting features. let's there 2 accounts , want transfer money between these 2 accounts. acc1(id 1) acc2(id 2). want transfer money 1 2. have transactions table. transfer, insert 2 rows transactions table. first transaction takes money acc1 , second transaction puts money acc2. how connect these 2 transactions? need id same these 2 transactions. transactionid field auto increment, can't know id. can create sequence of random numbers in mod 10000 everytime have check if there transaction generated id. appreciated.
you have new table transfers. like:
create table transfers ( id int auto_increment primary key, from_transaction_id int, to_transaction_id int, unique index from_to (from_transaction_id, to_transaction_id), foreign key from_transaction_id references transactions (id), foreign key to_transaction_id references transactions (id) ); after add withdrawal , deposit transactions transactions table, can add row transfers ids of 2 transactions.
Comments
Post a Comment