2013年12月17日 星期二

SQL ORDER BY with LIKE

SELECT name 
FROM table 
WHERE name LIKE "%John%" 
ORDER BY (CASE WHEN name = "John" THEN 1 WHEN name LIKE "John%" THEN 2 ELSE 3 END),name LIMIT 10 ;


參考資料:
http://stackoverflow.com/questions/10070508/sqlite-like-order-by-match-query

2013年12月10日 星期二

input radio 點文字checked

<input type="radio" id="sex1" name="sex" value="M"  /><label for="sex1">male</label>

<input type="radio" id="sex2" name="sex" value="F"  /><label for="sex2">female</label>




參考資料:
http://blog.xuite.net/bluishbox/code/61378093-%5BHTML%5D+%E9%BB%9E%E9%81%B8+radio+%E5%BE%8C%E8%AE%8A%E8%89%B2


http://www.blueshop.com.tw/board/show.asp?subcde=BRD20081001220501J6M



http://pattyshih66.pixnet.net/blog/post/145680918-%E2%92%BF-%E4%BD%BF%E7%94%A8javascript%E5%8F%96%E5%BE%97radio%E5%92%8Cselect%E7%9A%84%E5%80%BC

2013年12月4日 星期三

Ajax + PHP + Jquery onblur

A.php
<script> 
  $(document).ready(function(){
//檢查帳號是否存在
$('#username').blur(function(){
var acc = document.getElementById("username").value;
$.ajax({url: '../db_select/db_member.php?acc='+acc, type: 'GET'})
  .done(function(response){
var msg = response; //因型態問題,須設置在變數中
if(msg == "no"){ //帳號不存在
$('#username').css({
'color' : '#F00'
});
$('#username').val('無此帳號!');
}
  });
});
});
</script>
<input name="username" type="text" id="username" />


db_member.php

$acc = "-1";
if (isset($_GET['acc']) && $_GET['acc'] != "") {
  $acc = (get_magic_quotes_gpc()) ? $_GET['acc'] : addslashes($_GET['acc']);
}
mysql_select_db($database_labor, $labor);
$sql = sprintf("SELECT acc FROM memberWHERE acc= '%s'", $acc);
$result = mysql_query($sql, $labor);
$row = mysql_fetch_assoc($result);
$total = mysql_num_rows($result);

if($total > 0){
echo "yes";
}else{
echo "no";
}

此時db_member.php就會回傳到A.php接收



參考資料:
http://stackoverflow.com/questions/12384166/send-ajax-request-when-textfields-onblur-event-is-fired

http://stackoverflow.com/questions/10886782/ajax-checking-username-onblur