Jump to content

wordpress table insert with multiple rows out of 1 record


norus

Recommended Posts

I need some help with following WP query and insert. Query $arrAddress generates 1 record with address data from a address table. That works fine. Second query check if $user_id is present in testament table. If not present it must insert the data from address table into testament table. I only do not know how to get the address data into table testament. Each address must get a record in testament table. Fields in wp_mm_testament are: userid, field_id, field_value Means after insert, i get:

90, '3' => $arrAddress['first_name']

90, '4' => $arrAddress['last_name']

90, '5' => $arrAddress['gender']

90, '6' => $arrAddress['street_address']

90, '7' => $arrAddress['zipcode']

90, '8' => $arrAddress['city']

90, '9' => $arrAddress['country']

 

Hope someone of you with more experience then me can help me. Thanks in advance.

 

print_r($arrAddress) output:

stdClass Object ( [id] => 3 [user_id] => 100 [gender] => m [first_name] => Meindert Hendrik [last_name] => Heide Groot [street_address] => Huizenbrink 12 [zipcode] => 8929GH [city] => Eibergen [country] => Nederland )

 

$arrAddress = $GLOBALS['wpdb']->get_row('SELECT * FROM wp_mm_users_address WHERE user_id = "'.$user_id.'" ');
$arrTestament = $GLOBALS['wpdb']->get_row('SELECT userid FROM wp_mm_testament WHERE userid = "'.$user_id.'" ');

if(count($arrTestament) == 0) { // fields in wp_mm_testament are: userid, field_id, field_value

if(count($arrAddress) > 0) { // wp_mm_users_address has address of user $user_id
['wpdb']->insert('wp_mm_testament', array(
'userid' => $user_id, '3' => $arrAddress['first_name'],
'userid' => $user_id, '4' => $arrAddress['last_name'],
'userid' => $user_id, '5' => $arrAddress['gender'],
'userid' => $user_id, '6' => $arrAddress['street_address'],
'userid' => $user_id, '7' => $arrAddress['zipcode'],
'userid' => $user_id, '8' => $arrAddress['city'],
'userid' => $user_id, '9' => $arrAddress['country']));
}
}

 

Link to comment
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.