Migrating table contents to the other table and changing the rules of the game Mysql
I'm stuck yet again with mysql :)
My issue is simple/complicated at the same time.
I prepared dataset which contains columns:
user_id, user_email, user_country
.......
I need to import/insert this into wp_usermeta table.
wp_usermeta has following columns:
umeta_id (autoincrement), user_id, meta_key, meta_value
So from my dataset, user_id should be user_id, user_email and user_country become meta_keys and their content meta_values.
In the end I expect to get this:
user_id meta_key meta_value
12 user_country Italy
12 user_email [email protected]
From the lack of correct word for this, I'm trying to "deconstruct" dataset.
Possible with mysql? or should I do php script that will do this for me?
Solutions
I believe you're looking to do this with a php loop .
Create a query within your script that grabs all of the rows you're looking to bring over.
And then do a
while
loop that traverses over the results and within that you can do a foreach loop that pulls out the key and value.
Look at the PHP manuel for
mysqli_fetch_array
. Also, look at this example in particular.