Skip to content

Latest commit

 

History

History
179 lines (154 loc) · 5.59 KB

程式碼片段(未歸檔).md

File metadata and controls

179 lines (154 loc) · 5.59 KB

程式碼學習歸檔

jquery

// 取得id 元素內的文字
$(#id).text();

// 日期重組
var jsGetDateArray = $("#getdate"+nid).text().split("-");
var jsGetDate = new Date(jsGetDateArray[0], jsGetDateArray[1]-1, jsGetDateArray[2]);

// 按鈕按下不作用
function chkSurveyor(event) {
    alert( "Handler for .submit() called." );
    event.preventDefault();
}

function init() {
    'use strict';
    $("#formMod").submit(function(){
        chkSurveyor()
    });
}

window.onload = init;

javascript

// 使欄位不得輸入數字以外的字元
window.onload = onlyNumber;
function onlyNumber() {
    // 注意 keypress 與 keyup 的 keyCode 定義不同
    $(".onlyNumber").on("keyup blur",function(e) {
        // targetElement 可用 this 代替
        var targetElement = e.target || e.srcElement;
        // console.log(e.keyCode);
        // console.log(this);
            //鍵盤數字鍵
        if ((e.keyCode >= 48 && e.keyCode <=57)||
            //右方數字鍵盤
            (e.keyCode >= 96 && e.keyCode <=105)||
            //backspace delete tab
            (e.keyCode===8||e.keyCode===46||e.keyCode===9||e.keyCode===13)||
            // arrow up down left right
            (e.keyCode >= 37 && e.keyCode <=40)) {
            return;
        } else {
            event.preventDefault();
            // 這邊注意Jquery的套用需要$()開頭,僅有$是不可用的
            $(targetElement).val($(targetElement).val().replace(/[\D]/ig,""));
        }
    });
}

PHP

//  在fetch preparestmt 時可否再 使用prepared statement(PHP 5.2不作用)
while(mysqli_stmt_fetch($prepareStmt)) {
    // 將修改日期後的total值重新計算
    unset($RS_afterDate);
    $RS_afterDate = array();
    array_push($RS_afterDate, $id, $list_id, $num_in, $num_out, $total, $date);
    array_push($this -> array_RS, $RS_afterDate);
    $queryInProcess = "UPDATE crmember.book_inout set total=? where id = ? ";
    $prepareStmtInProcess = mysqli_prepare($db,$queryInProcess);

    // 將變數塞入問號內
    mysqli_stmt_bind_param($prepareStmtInProcess, "ss" ,$this -> new_total,$RS_afterDate[0]);
    mysqli_stmt_execute($prepareStmtInProcess);
    $this -> new_total = $this -> new_total - $RS_afterDate[3] + $RS_afterDate[2];
    mysqli_stmt_close($prepareStmtInProcess);
}


// 目前使用:先存到array 再執行
while(mysqli_stmt_fetch($prepareStmt)) {
    // 將修改日期後的total值重新計算
    unset($RS_afterDate);
    $RS_afterDate = array();
    array_push($RS_afterDate, $id, $list_id, $num_in, $num_out, $total, $date);
    //計算出之後的total值
    $this -> new_total = $this -> new_total - $RS_afterDate[3] + $RS_afterDate[2];
    array_push($this -> array_RS, $this -> new_total,$RS_afterDate[0]);
}

for ($i=0; $i <sizeof($this -> array_RS)/2 ; $i++) { 
    $queryInProcess = "UPDATE crmember.book_inout set total=? where id = ? ";
    $prepareStmtInProcess = mysqli_prepare($db,$queryInProcess);
    // 將變數塞入問號內
    mysqli_stmt_bind_param($prepareStmtInProcess, "ss" ,$this -> array_RS[$i*2],$this -> array_RS[($i*2)+1]);
    mysqli_stmt_execute($prepareStmtInProcess);
    mysqli_stmt_close($prepareStmtInProcess);
}

if (get_resource_type($db->connection) != "mysql link") {
    $db = MySQL::connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_CHAR_SET);
}

// 移動檔案
// $_FILES 接收HTML 上傳檔案之陣列
move_uploaded_file();

class Person {
    public $isAlive = true;
    public $firstname;
    public $lastname;
    public $age;

    public function __construct($firstname,$lastname,$age) {
        $this->firstname = $firstname;
        $this->lastname = $lastname;
        $this->age = $age;
    }
    
    public function greet(){
        return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)";
    }
}

$teacher = new Person("boring", "12345", 12345);
$student = new Person("John", "Lin", 12);

// exception
$i = 0;
try{
    while(mysqli_stmt_fetch($prepareStmt)) {
        if ($i++ < 1) {
            // array_push($resultSet, iconv("BIG5","UTF-8",$ship_type));
            unset($RS_beforeDate);
            $RS_beforeDate = array();
            array_push($RS_beforeDate, $no, $id, $list_id, $num_in, $num_out, $total, $date, iconv("BIG5","UTF-8",$note), $mod_pid, $mod_atime);
            $this -> new_total = $RS_beforeDate[5]-$RS_beforeDate[4]+$RS_beforeDate[3];
        } else {
            throw new Exception('result just can be one row!!!!');
        }
    }
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage();
    exit();
}

function chkOneRow($resultIn)
{
    try {
        if (mysql_num_rows($resultIn->_result) == 1) {
            //doSomething...
            return true;
        } else {
            throw new Exception('Oops! Something went wrong. Please contact CR IT Section.');
        }// if
    } catch (Exception $e) {
        echo $e->getMessage();
        exit();
    } //catch
}

// select 選單 若資料庫資料為某值,則在選單內選取起來
function selectOption($optArray, $val) 
{
    foreach ($optArray as $key => $value) {
        if ($val == $value) {
            $select = "selected";
        } else {
            $select = "";
        }
        echo "<option " . $select . ">" . $value . "</option>";
    }
}
// 使用方式,陣列為option的所有選項,第二個參數代資料庫被選取的值
$arr = array("","Y","N");
selectOption($arr, $record['abacc_flag']);