String string 是一系列字元。在 PHP 中,字元和字節一樣,也就是說,一共有 256 種不同字元的可能性。這也暗示 PHP 不支援 Unicode 。 常用單引號 (‘) 或雙引號 (“) 來定義一字串 $Str = ‘This is a string’; $Str =“This is also a string”; 連接兩個字串以用“ .”( 點 ) 運算符連接。 $Str1 = “This is a string”; $Str = $Str1 . “ with some more text”; // $Str 內容為 This is a string with some more text
Array 可以將 Array想像成一串貼有標籤的火車廂,標籤就是 Array 的 index ,而車廂內的裝的東西就是 Array 的 element/value 。 通常應用在需要記錄大量具有相同性質的資料時。 Example 1 :學生成績 在 PHP 中, Array 的 index 不需要一定是從 0 開始,也不需是正整數,可以為 String ,更可以混合使用; value 更可以是各種型別的資料。 Example 2 : 0 2 FF 1 B C A 100 Sue 1.2 Tim car May 200 0 1 6 5 4 3 2 80 90 86 83 87 92 88
29.
Array 定義一 Array的方式有: 使用 array() 函式。 透過 index 。 // 單純設值 // 使用 array() $animals = array( "cat", "dog", "bird" , "turtle" ); // 利用 index $animals[0] = "cat"; $animals[1] = "dog"; $animals[2] = "bird"; $animals[3] = "turtle"; // 指定 index // 使用 array() $fruit = array ("o"=>"orange", "b"=>"banana" , "a"=>"apple" ); // 利用 index $fruit["o"] = "orange"; $fruit["b"] = "banana"; $fruit["a"] = "apple"; Question : if we defined $array = array( 1, 1, 1, 1, 1, 8=>1, 4=>1, 19, 3=>13) , what indexs/values are in the $array?
PHP 流程控制 If .. else switch While do..while for foreach Break continue
34.
If .. else基本架構為 if (expr){ statements1 }else{ statements2 } 如果 expr 為正確則執行 statement1 ,否則執行 statement2 。 $a =10; $b = 9; if ($a > $b) { print "a is bigger than b"; } else { print "a is NOT bigger than b"; } $a =10; $b = 10; if ($a > $b) { print "a is bigger than b"; } else { print "a is NOT bigger than b"; }
35.
switch 基本架構為 switch (var) { case cond1 : statements1 case cond2 : statements2 … } 如果變數 var 與某一 cond 相同,則執行該段 statement 。 switch 語句一行接一行地執行。開始時沒有代碼被執行。僅當一個 case 語句中的 cond 和 switch 變數的值匹配時 PHP 才開始執行語句,直到 switch 的程序段結束或者遇到第一個 break 語句為止。 如果不在 case 的語句段最後寫上 break 的話, PHP 將繼續執行下一個 case 中的語句段。
36.
switch switch 語句和具有同樣表達式的一系列的 IF 語句相似,以底下兩段程式碼為例。 if ($i == 0) { print "i equals 0"; } if ($i == 1) { print "i equals 1"; } if ($i == 2) { print "i equals 2"; } switch ($i) { case 0: print "i equals 0"; case 1: print "i equals 1"; case 2: print "i equals 2"; } /* switch structure with break would more efficient */ switch ($i) { case 0: print "i equals 0"; break; case 1: print "i equals 1"; break; case 2: print "i equals 2"; } switch 通常會搭配 break 使用,以增加效率。
37.
While 基本架構為 while (expr) { statements } 如果 expr 為正確則執行 statement ,之後再檢查 expr 是否為正確,重覆此動作直到 expr 不為正確為止。 $i = 1; while ($i <= 10) { print $i++; /* the printed value would be $i before the increment (post-increment) */ } //12345678910 $i = 11; while ($i <= 10) { print $i++; /* the printed value would be $i before the increment (post-increment) */ } //
HTML 概念 HTML的全名是 HyperText Markup Language 。 1982 年, Tim Berners-Lee 為使世界各地的物理學家能夠方便的進行合作研究,建立了使用於其系統的 HTML 。 利用 HTTP ( HyperText Transfer Protocol) 網路通訊協定,便能夠在世界各地透過 WWW (World Wide Web) 的架構做跨平台的交流。 HTML 不是一種程式語言,而是透過在文章中插入標籤 (Tags) 來賦予文字一些特性,如標題,段落,連結等。
Form 表單( Form)是 HTML 的一個重要標籤。 表單不只是有呈現資訊的功能,更重要的是,它包含了數種表單元素( Form Elements ),可以 讓使用者進行資料填寫或選取的功能 ,並將使用者所填寫的資料送到伺服器端,進行必要的處理。 因此我們可以說,表單就是客戶端和伺服器進行資訊溝通的第一個門面。 表單傳遞方法有兩種,分別為 POST 與 GET 。
Select Data selectAWARD_COUNT FROM `award_count` where STU_NO='970001'; 查詢資料 查詢資料 select * FROM `depart` where IS_USED = '1' Order by DIV_KEY;
95.
Select Data 查詢資料Select DIV_KEY , count(DEPT) FROM `depart` where IS_USED = '1' group by DIV_KEY Order by DIV_KEY DESC;
96.
UPDATE 更新資料 UPDATE[LOW_PRIORITY] tbl_name SET col_name1=expr1,col_name2=expr2,... [WHERE where_definition] [LIMIT #]
97.
Update Data Update`depart` set IS_USED = '0' where DIV_KEY='ENGI'; 更新資料 Update `depart` set IS_USED = '1' where DIV_KEY <> 'ENGI'; 更新資料
98.
DELETE 刪除資料 DELETE[LOW_PRIORITY] FROM tbl_name [WHERE where_definition] [LIMIT rows] Delete from `depart` where IS_USED = '0' ; 刪除資料
99.
PHP + MySQLPHP 有函式庫可連接 MySQL 資料庫伺服器,並且提供多項功能。 如果你已安裝好了 PHP 與 MySQL 卻無法順利使用 PHP 的 mysql 函式庫,檢查您的 php.ini 檔案中“ extension=php_mysql.dll“ 之前是否有 "; " 符號,有則去掉此符號。
100.
mysql 函式庫 //連結 MySQL $link = mysql_connect("mysql_host", "mysql_user", "mysql_password") or die("Could not connect"); // 選擇 Database mysql_select_db("my_database") or die("Could not select database"); 連結 MySQL 並選擇 Database // 執行 SQL $result = mysql_query("Select DEPT_NAME_EN FROM `depart` where DEPT = 'CS'") or die("Query failed"); 執行 SQL