Toggle main menu visibility
新聞
下載
教材
影音
討論
其他選單
好站連結
行事曆
電子相簿
常見問題
萬用表單
即時留言簿
友站消息
社大學員
:::
登入
登入
帳號
密碼
登入
重整畫面
:::
所有書籍
「[1062] PHP7入門」目錄
MarkDown
8-11 templates/op_search_form.tpl
1. 建構開發環境與系統規劃
1-1 Visual Studio Code編輯器完整設定
1-2 各種訊息整理
1-3 test.php
1-4 index.php
1-5 templates/index.tpl
2. 寫入資料到資料庫
2-1 templates/index.tpl
2-2 templates/admin.tpl
2-3 css/my.css
2-4 admin.php
3. 資料庫讀取與程式的整併
3-1 admin.php
3-2 index.php
3-3 function.php
3-4 templtes/index.tpl
4. 加入登入及管理功能
4-1 header.php
4-2 footer.php
4-3 index.php
4-4 admin.php
4-5 templtes/header.tpl
4-6 templtes/footer.tpl
4-7 templtes/index.tpl
4-8 templtes/admin.tpl
4-9 templates/op_show_article.tpl
4-10 templates/op_list_article.tpl
4-11 css/my.css
4-12 signup.php
4-13 templtes/signup.tpl
5. 編輯器及上傳縮圖
5-1 includes/mailsender.php
5-2 config.php
5-3 verifyuser.php
5-4 signup.php
5-5 header.php
5-6 admin.php
5-7 main_login.php
5-8 loginheader.php
5-9 index.php
5-10 css/my.css
5-11 templates/nav.tpl
5-12 templates/admin.tpl
5-13 templates/index.tpl
5-14 templates/signup.tpl
5-15 templates/verifyuser.tpl
5-16 templates/main_login.tpl
5-17 templates/op_article_form.tpl
5-18 ckeditor/config.js
5-19 elFinder/elfinder_cke.php
6. 使用上傳物件及管理功能
6-1 admin.php
6-2 index.php
6-3 templates/nav.tpl
6-4 templates/index.tpl
6-5 templates/admin.tpl
6-6 templates/footer.tpl
6-7 templates/op_article_form.tpl
6-8 templates/op_list_article.tpl
6-9 templates/op_show_article.tpl
6-10 css/my.css
6-11 reporter.sql
7. 多人合作開發
7-1 admin.php
7-2 index.php
7-3 function.php
7-4 templates/op_modify_article.tpl
7-5 templates/op_article_form.tpl
7-6 templates/op_modify_article.tpl
7-7 .gitignore
8. 文章分頁及搜尋
8-1 index.php
8-2 function.php
8-3 PageBar.php
8-4 search.php
8-5 css/my.css
8-6 templates/op_show_article.tpl
8-7 templates/op_list_article.tpl
8-8 templates/nav.tpl
8-9 templates/search.tpl
8-10 templates/op_search_article.tpl
8-11 templates/op_search_form.tpl
9. JOIN資料表及寄信功能
9-1 search.php
9-2 function.php
9-3 admin.php
9-4 templates/op_search_article.tpl
9-5 templates/op_show_article.tpl
9-1 search.php
\[1062\] PHP7入門 =============== ### 一、 先完成上星期未完成的部份 1. 先關閉錯誤訊息,避免登入的ajax被卡住 2. 加入分頁、上下頁功能、完成多關鍵字搜尋功能 ### 二、 用join一次抓取兩個以上的資料表資料 1. [先下載缺少的檔案](https://www.tad0616.net/uploads/tad_book3/file/43/street_news.zip),並在function.php補上: ``` //讀出所有類別 function list_topic() { global $db, $smarty; $sql = "SELECT * FROM `topic` ORDER BY `topic_sn` "; $result = $db->query($sql) or die($db->error); $all = []; $i = 0; while ($data = $result->fetch_assoc()) { $all[$i] = $data; $i++; } //die(var_export($all)); list_topic_status(); $smarty->assign('all', $all); } //讀出所有TOPIC_status function list_topic_status() { if (!isset($smarty)) { global $smarty; } //狀態值增刪記得修改TABLE值 $status = ['開始投稿', '當期', '一般', '關閉']; $smarty->assign('topic_status', $status); } ``` 2. 在nav.tpl加上 ```
專題設定
``` 3. 下載[admin.zip](https://www.tad0616.net/uploads/tad_book3/file/43/admin.zip)及[templates.zip](https://www.tad0616.net/uploads/tad_book3/file/43/templates.zip),覆蓋原檔,這是文章發布的部份。 4. 當兩個資料表的欄位有關連時才能用join,例如topic分類資料表的topic\_sn以及article中的topic\_sn,欄位名稱不一定要相同,但代表的意義必須一樣。SQL語法為: ``` SELECT a.*, b.* FROM 左表 AS a JOIN 右表 AS b ON a.欄位 = b.欄位 WHERE 條件 ``` 5. 若關聯的欄位名稱一樣,亦可以用「`USING 欄位`」來取代「`ON a.欄位 = b.欄位`」 6. 假設有這兩個表:
**article**
**topic**
sn
topic\_sn
title
topic\_sn
topic\_title
1
1
文章1
1
分類1
2
1
文章2
2
分類2
3
1
文章3
4
分類4
4
3
文章4
5
3
文章5
6
4
文章6
7. 以MySQL來說,常用的join有四種: - (1) `JOIN`:左右表都要有資料才會取出 ``` SELECT a.*, b.* FROM article AS a JOIN topic AS b ON a.topic_sn= b.topic_sn ``` 結果為
**sn**
**topic\_sn**
**title**
**topic\_title**
1
1
文章1
分類1
2
1
文章2
分類1
3
1
文章3
分類1
6
4
文章6
分類4
- (2)` LEFT JOIN`:以左表為主,右表有就取出,沒有就空白。 ``` SELECT a.*, b.* FROM article AS a LEFT JOIN topic AS b ON a.topic_sn= b.topic_sn ``` 結果為
**sn**
**topic\_sn**
**title**
**topic\_title**
1
1
文章1
分類1
2
1
文章2
分類1
3
1
文章3
分類1
4
3
文章4
NULL
5
3
文章5
NULL
6
4
文章6
分類4
- (3) `RIGHT JOIN`:以右表為主,左表有就取出,沒有就空白。 ``` SELECT a.*, b.* FROM article AS a RIGHT JOIN topic AS b ON a.topic_sn= b.topic_sn ``` 結果為
**sn**
**topic\_sn**
**title**
**topic\_title**
1
1
文章1
分類1
2
1
文章2
分類1
3
1
NULL
分類2
6
4
文章6
分類4
- (4) `FULL JOIN`:左右表只要其中一個有資料就會取出。( FULL JOIN是 LEFT JOIN 與 RIGHT JOIN 的聯集. 但MySQL沒有直接支援 FULL JOIN,故用 [UNION](http://webdesign.kerthis.com/sql/sql_union) 來得到同樣的結果 ) ``` SELECT a.*, b.* FROM article AS a LEFT JOIN topic AS b ON a.topic_sn= b.topic_sn UNION SELECT a.*, b.* FROM article AS a RIGHT JOIN topic AS b ON a.topic_sn= b.topic_sn ``` 結果為
**sn**
**topic\_sn**
**title**
**topic\_title**
1
1
文章1
分類1
2
1
文章2
分類1
3
1
文章3
分類1
NULL
2
NULL
分類2
4
3
文章4
NULL
5
3
文章5
NULL
6
4
文章6
分類4
### 三、 寄信機制 1. PHP可以透過`mail()`來寄信,前提是主機本身要設定好機信機制,不管是用SMTP或sendmail其語法如下: ``` mail($收信人的Email, $主旨, $信件內容, $headers); ``` 2. 一般而言,寄信內容是純文字的,若要使用網頁語法,那麼必須設定`$headers` ``` $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; ``` 3. 若要帶附檔,則需要先將檔案編碼,或者直接改用PHPMailer來處理。 ### 四、 下拉選單、單複選的預設值寫法 1. select用`selected`,radio和checkbox用`checked`,一般我們直接在樣板中判斷即可 ```
類別
主題
``` ### 五、 友善列印(或其他分享按鈕) 1.
2. 點擊「Get the button code for」選擇「Any site」,然後點擊Choose Services…設定需要的服務(友善列印為printfriendly),點擊「Get Button Code」複製語法,並貼到樣板檔即可。
:::
搜尋
search
進階搜尋
QR Code 區塊
快速登入
所有討論區
「PHP全端開發」線上課程討論區
XOOPS使用討論區
一般研習學員
社大學員專用
路過哈啦區
XOOPS佈景設計
XOOPS模組開發
Tad書籍區
即時留言簿
書籍目錄
展開
|
闔起
線上使用者
83
人線上 (
18
人在瀏覽
線上書籍
)
會員: 0
訪客: 83
更多…