Tanja Posted February 16, 2015 Share Posted February 16, 2015 I want to insert two dataset into two tables. The first one is working fine, here i need the id for the second one. Array for insert looks like Array ( [1] => Array ( [name] => Excalibur from Bandit's World [id] => 15942 [class] => baby [qualification] => vv [place] => 1 [CAC] => 1 [BOB] => 1 [special] => testtitel [CACIB] => 0 [BOS] => 0 [BIS] => 0 [BOG] => 0 [BOD] => 0 [JVDHCh] => 0 [VDHCh] => 0 [VetVDHCh] => 0 [resCAC] => 0 [resCACIB] => 0 [resJVDHCh] => 0 [resVDHCh] => 0 [resVetVDHCh] => 0 ) [2] => Array ( [name] => Floyd from Bandit's World [idneu] => 16127 [class] => puppy [qualification] => vv [place] => 2 [special] => [CAC] => 0 [CACIB] => 0 [BOB] => 0 [BOS] => 0 [BIS] => 0 [BOG] => 0 [BOD] => 0 [JVDHCh] => 0 [VDHCh] => 0 [VetVDHCh] => 0 [resCAC] => 0 [resCACIB] => 0 [resJVDHCh] => 0 [resVDHCh] => 0 [resVetVDHCh] => 0 ) ) and the rows in databasetable are INSERT INTO xxxx ( show_id, dog_id, show_class, qualification, place, special, CAC, CACIB, BOB, BOS, BIS, BOG, BOD, JVDHCh, VDHCh, VetVDHCh, resCAC, resCACIB, resJVDHCh, resVDHCh, resVetVDHCh, add_by ) the first one (show_id) is the id of first insert, getting with $insert_id = $conn->lastInsertId(); add_by will taken from Session. The Array could be for one but also for 25 or more dogs, evertime the same things. Variables from array f.e. can be called with $_POST['dog'][1]['id'] $_POST['dog'][1]['class'] $_POST['dog'][1]['qualification'] How can i insert in loop or other? Number of dogs (at all) is in sessionvariable, too. Thanks for help Quote Link to comment Share on other sites More sharing options...
requinix Posted February 16, 2015 Share Posted February 16, 2015 IIRC the auto-incremented IDs for multiple INSERTs are guaranteed to be sequential - so long as you don't muck about with the table's current AUTO_INCREMENT value. So $insert_id and $insert_id+1. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.