2009年9月17日 星期四

[php]刪除陣列內相同的值

在PHP函式庫裡array_unique()可以達成刪除陣列內相同值之目的。
但是!我們來看一下說明

array_unique --- 從陣列移除相同的值

語法 : array array_unique (array array)

說明 :

Array_unique( )取輸入的陣列array且傳回沒有相同的值的陣列。索引會被保留(preserved)
意思就是他挖的洞就留在那邊= =
所以直接將陣列輸出的話,會得到很多的空列,因此我們要搭配另一個函式array_values()。

array_values --- 傳回陣列所有的值

語法 : array array_values(array input);

說明 :

此函式從陣列array傳回所有的值。

它回傳的仍是一個陣列喔,但是它只把有值的部分傳出,如此便能得到沒有洞的陣列囉。

for($i=0;$i<100;$i++){
$a[$i] = rand(0,300);
}
$b = array_values(array_unique($a));

2009年9月16日 星期三

[jQuery]網頁部分列印--jqPrint

『不想整面列印,只想印部分範圍嗎?』

jqPrint是跟據之前jPrintArea改寫的,兩者皆是jQuery的plugin,後者目前已停止提供下載了。

網頁載入jquery.js及jqprint.js後可依下面指令達成部分列印

$('#divTest1').jqprint();


利用$('#printDivId')可印出指定ID的DIV內容,如下例

<\div id="divTest1">I'll be printed.<\/div>
<\script>$('#divTest1').jqprint();<\/script>


另外,jqPrint可針對CLASS進行群組列印

<\div id="divTest1" class="printMe">I'll be printed.<\/div>
<\div id="divTest2" class="printMe">I'll be printed too!<\/div>
<\script>$('.printMe').jqprint();<\/script>

參考網頁
  • http://plugins.jquery.com/project/jqPrint
  • http://www.recoding.it/?p=138
  • http://www.recoding.it/wp-content/uploads/demos/jqprint-demo.htm
  • http://www.bennadel.com/index.cfm?dax=blog:1591.view

2009年9月15日 星期二

[SQL]distinct

SELECT DISTINCT s_id, id ,name, phone,address FROM users WHERE id>200
-->所有欄位皆不相同才會被移除
SELECT COUNT(DISTINCT s_id), id ,name, phone,address FROM users WHERE id>200
-->會呈現"一筆"告訴你有幾組不同s_id的資料
SELECT COUNT(DISTINCT s_id), id ,name, phone,address FROM users WHERE id>200 GRUOP BY s_id
-->以s_id分組呈現許多筆資料,且s_id相同的便會被移除

用COUNT只是一種手段,實際上我們也沒真要算有多少不同組,只是藉此對指定欄位做distinct,使用GRUOP BY是使資料分開來呈現,不然只會得到"一筆"資料。

DIV橫向置中

div{
text-align:center;/*IE*/
width:600;
margin:auto;
*width:auto;/*IE*/
*margin:0;/*IE*/
}


嚴格來說IE並不是把DIV置中,而是其中元素在DIV內置中,未設置width時DIV為整列,元素在"整列"上置中。
火狐則是明確利用width及左右margin來達到DIV置中。

*firefox不接受*width寫法

2009年7月16日 星期四

$response = new xajaxResponse();
$response->assign(元素ID,屬性,值);
return $response;

要注意是ID而非name....(ID才有唯一性的嘛)

[PHP]以前...跟現在...

$date = "2009-07-16";
$dates = explode("-", $date);
以前的我...

$dates[2]++;
if ($dates[1]=='1'||$dates[1]=='01'||$dates[1]=='3'||$dates[1]=='03'||$dates[1]=='5'||$dates[1]=='05'||$dates[1]=='7'||$dates[1]=='07'||$dates[1]=='8'||$dates[1]=='08'||$dates[1]=='10'){
 if ($dates[2]-31 > 0){
  $dates[2] = $dates[2] -31;
  $dates[1]++;
 }
}else if ($dates[1]=='12'){
 if ($dates[2]-31 > 0){
  $dates[2] = $dates[2] -31;
  $dates[1]=1;
  $dates[0]++;
 }
}else if($dates[1]=='4'||$dates[1]=='04'||$dates[1]=='6'||$dates[1]=='06'||$dates[1]=='9'||$dates[1]=='09'||$dates[1]=='11'){
 if ($dates[2]-30 > 0){
  $dates[2] = $dates[2] -30;
  $dates[1]++;
 }
}else if(($dates[0]%4 == 0) &&($dates[1]=='2'||$dates[1]=='02')){
 if ($dates[2]-29 > 0){
  $dates[2] = $dates[2] -29;
  $dates[1]++;
 }
}else if(($dates[0]%4 != 0) &&($dates[1]=='2'||$dates[1]=='02')){
 if ($dates[2]-28 > 0){
  $dates[2] = $dates[2] -28;
  $dates[1]++;
 }
}
$date = implode("-", $dates);

現在的我...
$date = date("Y-m-d", mktime(0,0,0,$dates[1],$dates[2]+1,$dates[0]));


這就叫做經驗的累積.......唉

2009年6月26日 星期五

javascript一行檢測瀏覽器

B=(function x(){})[-5]=='x'?'FF3':(function x(){})[-6]=='x'?'FF2':/a/[-1]=='a'?'FF':'\v'=='v'?'IE':/a/.__proto__=='//'?'Saf':/s/.test(/a/.toString)?'Chr':/^function \(/.test([].sort)?'Op':'Unknown'

參考網址
http://jsgears.com/thread-168-1-1.html
http://ajaxian.com/archives/ievv

zeroclipboard複數指定方法--改變大小

原先的reposition函式會提醒你
// reposition our floating div, optionally to new container
// warning: container CANNOT change size, only position
他只會移動位置並不會改變大小
當要指定的元素大小不一時,就有點麻煩了

回頭看在glue()裡創建新的DIV遮罩時會設定下列參數
style.position = 'absolute';
style.left = '' + box.left + 'px';
style.top = '' + box.top + 'px';
style.width = '' + box.width + 'px';
style.height = '' + box.height + 'px';
style.zIndex = zIndex;
而reposition()只有重新定義其中left及top的位置參數
所以可以在reposition()中加入設定width及height這兩行程式碼
但這兩行只是設定style的顯示
最重要的是這一行
this.div.innerHTML = this.getHTML( box.width, box.height );
它是將在getHTML()中寫好導入flash的html丟入div中,使它成為一個flash元件
重新呼叫此函式才能變更flash的大小

將上列三行加入reposition即可
不過在IE及FireFox上都運行無誤,在Chrome,Safari上則會卡卡的,Chrome有時會完全卡住
其他的瀏覽器我就沒去試了,這也是他為什麼不讓我們改變大小的原因吧

2009年6月25日 星期四

zeroclipboard複數指定方法

在firefox中預設是將剪貼簿關掉的,不像IE可以自由取用
在網路中翻了又翻找到了zeroclipboard!!
zeroclipboard解決了跨瀏覽器使用clipboard的問題
http://code.google.com/p/zeroclipboard/
之前也有使用flash的方法
http://www.jeffothy.com/weblog/clipboard-copy/
但到了flash10就無法使用
http://bshadow.pixnet.net/blog/post/23246050


下面原始碼出處http://bowser.macminicolo.net/~jhuckaby/zeroclipboard/multiple.html

<\html>
<\head>
<\title>Zero Clipboard Multiple Test<\/title>

<\style type="text/css">
body { font-family:arial,sans-serif; font-size:9pt; }

div.multiple {
float: left;
background-color: white;
width:200px; height:200px;
border:1px solid #ccc;
margin:5px;
cursor: pointer;
font-size: 14pt;
}

div.multiple.hover {
background-color: #ddd;
}
<\/style>

<\script type="text/javascript" src="./flash/jquery.js"><\/script>
<\script type="text/javascript" src="./flash/ZeroClipboard.js"><\/script>

<\script language="JavaScript">
var clip = null;

function init() {
ZeroClipboard.setMoviePath( './flash/ZeroClipboard.swf' );
// setup single ZeroClipboard object for all our elements
clip = new ZeroClipboard.Client();
clip.setHandCursor( true );

// assign a common mouseover function for all elements using jQuery
//將html 中宣告的div元素以class為單位丟入jQuery中
$('div.multiple').mouseover( function() {
// set the clip text to our innerHTML
clip.setText( this.innerHTML );

// reposition the movie over our element
// or create it if this is the first time
//這裡指的div是javascript產生的div元素,也就是附屬在clip底下的div,並非上一段所提到html的div,當程式呼叫到clip.glue()時js會產生一個div罩住你所指定的元素,所以這一段是在說如果先前已有產生div那麼便將他重新定位至現在指定的元素(this),否則就創造一個新的div遮罩
if (clip.div) {
clip.receiveEvent('mouseout', null);
clip.reposition(this);
}
else clip.glue(this);

// gotta force these events due to the Flash movie
// moving all around. This insures the CSS effects
// are properly updated.
clip.receiveEvent('mouseover', null);
} );

// add an event handler which fires after text is copied to the clipboard
// and change the color of the underlying DOM element
clip.addEventListener('complete', function(client, text) {
var div = client.domElement;
div.style.backgroundColor = '#bff';
} );
}
<\/script>


<\/head>

<\body onLoad="init()">
<\h1>Zero Clipboard Multiple Test<\/h1>

<\div class="multiple">Hello there<\/div>
<\div class="multiple">These are all equally sized DOM elements.<\/div>
<\div class="multiple">Click on any of them to copy their text to the clipboard.<\/div>
<\div class="multiple">This is all done with a single ZeroClipboard object.<\/div>

<\div class="multiple">The only catch is, all the elements must be the same size.<\/div>
<\div class="multiple">Bye bye!<\/div>
<\div style="clear:both;"><\/div>

<\br/><\br/>
You can paste text here if you want, to make sure it worked:<\br/>
<\textarea id="testarea" cols=50 rows=10><\br/>
<\input type=button value="Clear Test Area" onClick="document.getElementById('testarea').value = '';"/>

<\/body>

<\/html>


當初就是兩個div搞混了 所以改用td時就會有問題(做了兩個div遮罩出來)

by the way
IE只需要一行
window.clipboardData.setData("Text",A.innerText);

2009年6月22日 星期一

[PHP]mysql_real_escape_string

get_magic_quotes_gpc();
GPC--get,post,cookie
如果伺服器替參數值都加上//回傳true

$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

用stripslashes()刪除slash
//----------------------------------------------------------------------
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
如果輸入值含用',"等使之跳脫以免影嚮sql query 或造成漏洞

[PHP]避免重新載入或上下一頁的重覆輸入

表單用POST丟給自己來做就好了@@
< method="post" action="self.php">

------------------------------------------


<\html\>
<\body\>
<\form method="POST" action="xxxx.php"\>
<\input type="hidden" name="check" value="true"\>
<\input type="submit"\>
<\/form\>
<\/body\>
<\/html\>

太長太複雜的話用require的好了

2009年6月19日 星期五

開通!!

開通了 不知道好不好玩!?


不能使用style標籤....= =
也沒有script標籤 囧

2009年6月18日 星期四

發佈排程

哇咧....原來可以排時間才公佈文章
那我剛才第一篇打的「開通!」不就是不是第一篇了....囧

javascript來亂

function confirmit(no,table,ymd,thisname){
var text = './etrc_ag_calendar_insert.php?method=confirm&no='+no+'&ymd='+ymd+'&table='+table;
var time_s = getNextElement(thisname);
var time_e = getNextElement(time_s);
var depart = getNextElement(time_e);
var memo = getNextElement(depart);
var temp = '&time_s='+time_s.value+'&time_e='+time_e.value+'&depart='+depart.value+'&memo='+memo.value.replace("&","\&");//避免被當成下一個元素

var query = text + temp;
// document.write(query);
location.href=query;