2009年6月25日 星期四

MySQL 使用 UTF-8 編碼時的中文排序

當資料庫編碼是使用 UTF-8 時,若有欄位是中文,且要依此欄位進行排序時,

MySQL將會依 UTF-8 的編碼來排序,而不會依我們所預期的 BIG5 來排序。

若要解決此問題,只要在排序時,將排序的欄位轉為 BIG5 就可以依筆畫排序了。

使用方式就是 CONVERT( 欄位名稱 using big5) 。

例如:

Select factory From wrongnote Order By CONVERT( factory using big5 )

.

2009年5月8日 星期五

JavaScript 寫入, 讀取, 刪除 Cookie 值

function SetCookie(name,value,expiry,path,domain,secure){
var NameString = name + "=" + value;
var ExpiryString = (expiry == null) ? "" : " ;expires = "+ expiry.toGMTString();
var PathString = (path == null) ? "" : " ;path = "+ path;
var DomainString = (path == null) ? "" : " ;domain = "+ domain;
var SecureString = (secure) ?";secure" :"";
document.cookie = NameString + ExpiryString + PathString + DomainString + SecureString;
}

function GetCookie(name) {
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}

function DelCookie(name){
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

2009年4月28日 星期二

MySQL 及 MsSQL 隨機選出資料

MySQL

select * from MyTable order by RAND()

MsSQL

select * from MyTable order by NEWID()

Access

select * from MyTable order by RND(數值型的列名稱)