jQuery 取物件座標 X,Y 相對位置&絕對位置

//絕對位置
$(‘.nav li > a’).hover(function(){
        var position = $(this).offset();
        var x = parseInt(position.left);
        var y = parseInt(position.top);

})

//相對位置

$(‘.nav li > a’).hover(function(){
        var position = $(this).position();
        var x = parseInt(position.left);
        var y = parseInt(position.top);


})[……]

閱讀更多

MySQL 自訂ORDER BY捱序或 ORDER BY 忽略

1. 只按日期排序,忽略年份
> select date, description from table_name order by month(date),dayofmonth(date);
注意:單純使用dayofyear來排序會導致錯誤,如2-29與非閏年的3-1日同等級

2. 排序點分式IP
> select ip from table_name order by inet_aton(ip);
或者在設計表時就使用int unsigned 來表示ip

3. 將某列中特定值排在最前
例如想把表中lulu的名字排在最前顯示,其他按字母排序
> select name from table_name order by if(name=’lulu’,0,1),name ;
也可以把if的條件根據需要換成相應的語句。

4. 將某列內容按照使用者自訂的順序排序
例如想把表中的名字按lulu,xixi,baba,mama的非常規順序排序輸出:
> select name from table_name order by field(name,’lulu’,’xixi’,’baba’,’mama’);

5. 對枚舉類型排序
枚舉類型預設為數字排序,如果希望以字串形式排序。
> select name from table_name order by cast(name as char);
如果希望更改enum的排序預設順序,可以alter table
alter table table_name modify name enum(‘lulu’,’xixi’,’mama’,’baba’);

6. csv類型的字串的某字串排序
例如某列m_str內容是形如abc-321-mno-jkl的形式,希望對第二列進行排序
> select m_str from table_name
order by substring_index(substring_index(m_str,’-‘,2),’-‘,-1);

[……]

閱讀更多

PHP 時間運算 日期或時間加減

字串格式的日期時間轉成Time

‘2015-03-04 12:03:25’這就是字串格式的日期時間,都要先轉為time加以運算,運算完成再用date()去格式化日期。
例如資料庫dateTime時間格式或timestamep時間格式,需先轉成time才有辦法做運算
/*
	https://vector.cool
*/
$time = strtotime('2015-03-04 12:03:25');
//output : 1425441805

以下提供三種方法進行日期時間加減運算

一、慢慢算

/*
	https://vector.cool
*/
date_default_timezone_set("Asia/Taipei");
$next_Month = 30*24*60*60;//30天*24小時*60分*60秒
echo date('Y-m-d',strtotime('2015-03-04 12:03:25')+$next_Month);

二、使用 mktime()

/*
	https://vector.cool
*/
date_default_timezone_set("Asia/Taipei");
$date=date("Y-m-d",mktime(hr,min,sec,mon,day,year))

//例如:今天再加5天
date("y-m-d",mktime(0,0,0,date("m"),(date("d")+5),date("y")))

Reference:http://php.net/manual/zh/function.mktime.php

三、使用 strtotime()

strtotime()這東西比我想像聰明多了耶

/*
	https://vector.cool
*/
date_default_timezone_set("Asia/Taipei");
echo strtotime("now")."<br/>";
echo strtotime("10 September 2000")."<br/>";
echo strtotime("2020-09-29 +1 day")."<br/>";
echo strtotime("+1 day")."<br/>";
echo strtotime("+1 week")."<br/>";
echo strtotime("+1 week 2 days 4 hours 2 seconds")."<br/>";;
echo strtotime("next Thursday")."<br/>";
echo strtotime("last Monday")."<br/>";

Reference:http://php.net/manual/zh/function.strtotime.php

[……]

閱讀更多