Wednesday, November 25, 2009

ORDER by title in mysql, ignoring the word “The”

Often time when you want to sort your sql return record by title, but the title starts with the word "The", for example "The Mummy" and we wants to sort by "Mummy" instead.
There are 2 solutions I have found:
1. Create a new field on the fly and sort by using the new field.
Select *, str_replace(title, 'The ', '') as sort_title ORDER BY sort_title

2. For better query performance, create a new column in the table ('sort_title') that is same as the title column but without a prefix of "The " or "A".

Some more info can be found here:

Monday, November 23, 2009

SSH tunneling

ssh -NL
now access via localhost:1090

Friday, November 20, 2009

Simple json object decoding

var newdata = eval('(' + jsonData + ')');

Thursday, November 19, 2009

PHP Date format in other language

To make php change data format dynamically base on the current language, use strftime() in combine with setlocale().
If local has not been installed, install it and restart Apache.
More info on