{"id":869,"date":"2016-01-21T17:16:43","date_gmt":"2016-01-21T08:16:43","guid":{"rendered":"http:\/\/n8finch.com\/?p=869"},"modified":"2016-08-25T10:59:34","modified_gmt":"2016-08-25T01:59:34","slug":"sql-database-queries-and-foreach","status":"publish","type":"post","link":"https:\/\/n8finch2024.local\/sql-database-queries-and-foreach\/","title":{"rendered":"This Week I Learned: SQL database queries and foreach()"},"content":{"rendered":"
It’s been a busy week.<\/p>\n
I’m putting together a new theme (to be unveiled soon), updating some projects I’ve been working on, and tuned my guitar for the first time in about three months.<\/p>\n
I’ve come across a\u00a0couple new things I wanted to record.\u00a0It’s funny how, when putting sites together, you come across things you could have used a couple projects ago. Seems to always happen.<\/p>\n
So, here’s to trying to stay ahead of the curve…<\/p>\n
One of my recent projects needed to be built fairly quickly and was quite data-intensive.\u00a0There was a massive migration of data, and it was iterated, which means that we added things about five or seven times, occasionally with different metadata.\u00a0We also\u00a0allowed for some new characters to be used in data that was previously filtered out.<\/p>\n
Needless to say, the data needed to be updated. Using phpMyAdmin, I was able to do this fairly quickly with some quieres:<\/p>\n
To update user login names:<\/p>\n
UPDATE wp_users SET user_login\u00a0= 'NewUserName' WHERE\u00a0user_login\u00a0= 'OldUserName';<\/pre>\nTo update usermeta fields:<\/p>\n
UPDATE wp_usermeta SET meta_key = 'NewMetaKey' WHERE meta_key = 'OldMetaKey';\r\n\r\nUPDATE wp_usermeta SET meta_value = 'NewMetaValue' WHERE meta_value = 'OldMetaValue';<\/pre>\nThere was plenty of\u00a0information to change and these queries made it all possible.<\/p>\n
foreach() Loop Syntax<\/h2>\n