This Week I Learned: SQL database queries and foreach()

This Week I Learned: SQL database queries and foreach()

It’s been a busy week.

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.

I’ve come across a couple new things I wanted to record. It’s funny how, when putting sites together, you come across things you could have used a couple projects ago. Seems to always happen.

So, here’s to trying to stay ahead of the curve…

SQL Queries in phpMyAdmin

One of my recent projects needed to be built fairly quickly and was quite data-intensive. There 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. We also allowed for some new characters to be used in data that was previously filtered out.

Needless to say, the data needed to be updated. Using phpMyAdmin, I was able to do this fairly quickly with some quieres:

To update user login names:

UPDATE wp_users SET user_login = 'NewUserName' WHERE user_login = 'OldUserName';

To update usermeta fields:

UPDATE wp_usermeta SET meta_key = 'NewMetaKey' WHERE meta_key = 'OldMetaKey';

UPDATE wp_usermeta SET meta_value = 'NewMetaValue' WHERE meta_value = 'OldMetaValue';

There was plenty of information to change and these queries made it all possible.

foreach() Loop Syntax

I’ve been following WPMUDev’s series on PHP. It’s been pretty good so far. Actually, this article from Daniel Pataki has clarified something I’ve been struggling with: the foreach() loop.

The basic loop can look something like this:

<pre>$names = array( "Nate Finch", "Someone Else", "Another Somone" );
echo "</pre>
<ul>"; foreach( $names as $name ) { echo "
	<li>" . $name . "</li>
</ul>
"; } echo "
<ul>
<ul>";</ul>
</ul>
//Don't include the pre-tags

I was always confused about the syntax, but knowing that $name and $names can be whatever variables you want, and then where to call those parameters (in a list, for example), it all just clicked.

It works the same when going through an associative array as well, something like: foreach( $details as $label => $value ), where $details is the name of the array, $label is the key, and $value is the key’s value.

I’m sure this syntax is almost exactly the same for Javascript (if I’m remembering correctly).

So, for the Learner I am, this has been a very good week.

###

Cheers,

Nate

Up Next

How Much Javascript is Enough?

How Much Javascript is Enough?