Jump to content

PDO Insert Array or ? increment variables


Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/294641-pdo-insert-array-or-increment-variables/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.