2013年5月1日 星期三

00_php語法備忘

PHP語法備忘


//起動session
session_start();

//使用者
$user_no=$_SESSION["idno"];
$user_name=$_SESSION["ch_name"];
$user_dept=$_SESSION["dept"];

//資料庫主機-連結:DB Server
include("DBServer_Con.php");



//取得變數
$get_smye=trim($_GET["smye"]);
$post_smye=trim($_POST["smye"]);


//[文字類]

若資料庫碼為big5 網頁utf-8 則須轉碼

$str_cname=iconv("big5","Utf-8",trim($row['chinese_name']));
$str_cname=iconv("utf-8","big5",$str_count_result);

//substr字串if (substr($str_UserID,0,1)=="R" || substr($str_UserID,0,1)=="D" ){
}else{
echo "<meta http-equiv=REFRESH CONTENT=0;url='Fun_ShowError.php?meg_txt=限碩士。'>";
exit;
}




//傳資料編碼解碼
$str_idno=base64_encode($idno);
$url=thisprg.php?idno=$str_idno;

$get_idno=trim($_GET["idno"]);
$get_idno=base64_decode($get_idno);



//邏輯判斷

if ($exam_kind=="2"){
}


//[資料庫]

//方式一
$SQL_Check="select count(*) as tota
                           from sch_books
                         where smye=$get_smye";
$result = sybase_query($SQL_Check,$DBCon);

if (!$result) die ("無法查詢資料(sch_books)");
$total = sybase_num_rows($result);
if ($total == 0){
 echo "無資料<BR><BR>";
 exit;
}

$row = sybase_fetch_array($result);
$int_check=$row["tota"];


//方式二
$SQL_Check="select *
                           from sch_books
                        where smye=$get_smye";
$result = sybase_query($SQL_Check,$DBCon);
while($row = sybase_fetch_array($result)){
    $book_name=$row["book_name"];
}

//四捨五入

EX 除結果是 22.2336 ==>22.23
$tota_dyu_sco=number_format($sum_dept_sco/$tota_pri,2,'.','');

EX 除結果是 22.2336 ==>22
$tota_dyu_sco=number_format($sum_dept_sco/$tota_pri,0,'.','');

//加入檔案
include('page_footer.php')


沒有留言:

張貼留言