How to Insert a MD5 Password (or the Result of Any Other MySQL Function) Into a Field with “Navicat for MySQL”

MySQL supports MD5() and some other cool functions that do the math for you and save the result in the table field, but what happens when you already have a database and the table in place and you are using “Navicat”, plus you don’t want to fiddle with raw SQL?

Luckily, Navicat has the so called “Raw Mode” when viewing a table’s rows which allows us to insert data using MySQL expressions/functions.

Here are the steps on how to insert a MD5()’ed password in a “users” table using Navicat:
1. Open your desired table with Navicat:

navicat raw 1

2. Choose “View->Raw Mode” from the top menu:

navicat raw 2

3. In your password field, type the expression, whose result you want inserted in that field, e.g.

MD5('newpassword')

navicat raw 3

4. Hit “Enter” and “Ctrl+S” to apply the changes. Optionally disable “Raw mode” from the menu if you need to go back to the regular mode.

navicat raw 4

Enjoy the result of the MD5, without using complex raw SQL queries that are prone to typos.


How to get a link to the still image of a YouTube video?

YouTube has multiple servers for serving images of the videos, hosted on the site. They are mainly used for load ballancing (so you get the image that is hosted on a server, that is physically closest to you so it loads faster).

However, as a developer or a website owner you may want to programmatically build a link to the thumbnail or still image that YouTube uses for a given video.

What you need is – the ID of the video (e.g. if the video in question is http://www.youtube.com/watch?v=m3JAtvsqfF8, the ID would be m3JAtvsqfF8). When you have the ID of the video, just replace it in the below URL and open it in your browser.

http://img.youtube.com/vi/video_id_here/0.jpg

You should immediately see the full-size thumbnail that YouTube uses across its website (note that scaled down versions are also available; just replace the last zero in the URL with “1.jpg”, “2.jpg” or “hqdefault.jpg”).


Counting the Number of Options/Elements in a <SELECT> Dropdown with jQuery

Let’s say you have this (very) simple <select> dropdown:


And one day you decide to figure out how much elements or <option> tags the given <select> has.

It’s easy:

var items = $('#my_dropdown option').length;
alert(items);

The above should immediately display “2″ since we have 2 countries in the select dropdown.


Find Value of Key in Associative Array

I recently stumbled upon the following issue – I had an associative array with key=>value type and I wanted to get the value of a specific key. I wasn’t able to find a suitable built-in PHP function, so I decided to write something of my own. Feel free to reuse it however you like.

Include this function anywhere in your PHP file:

function find_by_key($searched, $array){
	if(!is_array($array)) return FALSE; // We haven't passed a valid array
 
	foreach($array as $key=>$value){
		if($key==$searched) return $value; // Match found, return value
	}
	return FALSE; // Nothing was found
}

Then you can use it by following this example:

$sample_array = array(
	'bmw'=>'fast',
	'mercedes'=>'luxury',
	'audi'=>'expensive'
);
 
echo find_by_key('audi', $sample_array);

This example should output ‘expensive’. I hope you find this useful.