Toggle main menu visibility
新聞
下載
教材
影音
討論
其他選單
好站連結
行事曆
電子相簿
常見問題
萬用表單
即時留言簿
友站消息
社大學員
:::
登入
登入
帳號
密碼
登入
重整畫面
:::
所有書籍
「[1062] PHP7入門」目錄
MarkDown
8-2 function.php
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
8-4 search.php
\[1062\] PHP7入門 =============== ``` query($sql) or die($mysqli->connect_error); $total = $result->num_rows; $navbar = new PageBar($total, $show_num, $page_list); if (!empty($to_page)) { $navbar->set_to_page($to_page); } if (!empty($url_other)) { $navbar->set_url_other($url_other); } $mybar = $navbar->makeBar(); $main['bar'] = "
{$mybar['left']} {$mybar['center']} {$mybar['right']}
"; $main['sql'] = $sql . $mybar['sql']; $main['total'] = $total; return $main; } class PageBar { // 目前所在頁碼 public $current; // 所有的資料數量 (rows) public $total; // 每頁顯示幾筆資料 public $limit = 10; // 目前在第幾層的頁數選項? public $pCurrent; // 總共分成幾頁? public $pTotal; // 每一層最多有幾個頁數選項可供選擇,如:3 = {[1][2][3]} public $pLimit; // 要使用的 URL 頁數參數名? public $url_page = "g2p"; // 會使用到的 URL 變數名,給 process_query() 過濾用的。 public $used_query = array(); public $query_str; // 存放 URL 參數列 //指定頁面 public $to_page; //其他連結參數 public $url_other; public function __construct($total, $limit = 10, $page_limit) { $limit = intval($limit); //die(var_export($limit)); $mydirname = basename(dirname(__FILE__)); $this->to_page = $_SERVER['PHP_SELF']; $this->limit = $limit; $this->total = $total; $this->pLimit = $page_limit; } public function init() { $this->used_query = array($this->url_page); $this->query_str = $this->processQuery($this->used_query); $this->glue = ($this->query_str == "") ? '?' : '&'; $this->current = (isset($_GET[$this->url_page])) ? intval($_GET[$this->url_page]) : 1; if ($this->current < 1) { $this->current = 1; } $this->pTotal = ceil($this->total / $this->limit); $this->pCurrent = ceil($this->current / $this->pLimit); } // 處理 URL 的參數,過濾會使用到的變數名稱 public function processQuery($used_query) { // 將 URL 字串分離成二維陣列 $QUERY_STRING = htmlspecialchars($_SERVER['QUERY_STRING']); $vars = explode("&", $QUERY_STRING); //die(var_export($vars)); for ($i = 0; $i < count($vars); $i++) { if (substr($vars[$i], 0, 7) == "amp;g2p") { continue; } //echo substr($vars[$i],0,7)."
"; $var[$i] = explode("=", $vars[$i]); } // 過濾要使用的 URL 變數名稱 for ($i = 0; $i < count($var); $i++) { for ($j = 0; $j < count($used_query); $j++) { if (isset($var[$i][0]) && $var[$i][0] == $used_query[$j]) { $var[$i] = array(); } } } $vars = array(); // 合併變數名與變數值 for ($i = 0; $i < count($var); $i++) { $vars[$i] = implode("=", $var[$i]); } // 合併為一完整的 URL 字串 $processed_query = ""; for ($i = 0; $i < count($vars); $i++) { $glue = ($processed_query == "") ? '?' : '&'; // 開頭第一個是 '?' 其餘的才是 '&' if ($vars[$i] != "") { $processed_query .= $glue . $vars[$i]; } } return $processed_query; } // 製作 sql 的 query 字串 (LIMIT) public function sqlQuery() { $row_start = ($this->current * $this->limit) - $this->limit; $sql_query = " LIMIT {$row_start}, {$this->limit}"; return $sql_query; } public function set_to_page($page = "") { $this->to_page = $page; } public function set_url_other($other = "") { $this->url_other = $other; } // 製作 bar public function makeBar($url_page = "none") { if ($url_page != "none") { $this->url_page = $url_page; } $this->init(); // 取得其他連結參數 $loadtime = $this->url_other; // 取得目前頁框(層)的第一個頁數啟始值,如 6 7 8 9 10 = 6 $i = ($this->pCurrent * $this->pLimit) - ($this->pLimit - 1); $bar_center = ""; while ($i <= $this->pTotal && $i <= ($this->pCurrent * $this->pLimit)) { if ($i == $this->current) { $bar_center = " {$bar_center}
{$i}
(current)
"; } else { $bar_center .= "
{$i}
"; } $i++; } $bar_center = $bar_center . ""; // 往前跳一頁 if ($this->current <= 1) { //$bar_left=$bar_first=""; $bar_left = "
‹
"; $bar_first = "
«
"; } else { $i = $this->current - 1; $bar_left = "
‹
"; $bar_first = "
«
"; } // 往後跳一頁 if ($this->current >= $this->pTotal) { //$bar_right=$bar_last=""; $bar_right = "
›
"; $bar_last = "
»
"; } else { $i = $this->current + 1; $bar_right = "
›
"; $bar_last = "
»
"; } // 往前跳一整個頁框(層) if (($this->current - $this->pLimit) < 1) { $bar_l = ""; } else { $i = $this->current - $this->pLimit; $bar_l = ""; } //往後跳一整個頁框(層) if (($this->current + $this->pLimit) > $this->pTotal) { $bar_r = ""; } else { $i = $this->current + $this->pLimit; $bar_r = ""; } $page_bar['center'] = $bar_center; $page_bar['left'] = $bar_first . $bar_l . $bar_left; $page_bar['right'] = $bar_right . $bar_r . $bar_last; $page_bar['current'] = $this->current; $page_bar['total'] = $this->pTotal; $page_bar['sql'] = $this->sqlQuery(); return $page_bar; } } ```
:::
搜尋
search
進階搜尋
QR Code 區塊
快速登入
所有討論區
「PHP全端開發」線上課程討論區
XOOPS使用討論區
一般研習學員
社大學員專用
路過哈啦區
XOOPS佈景設計
XOOPS模組開發
Tad書籍區
即時留言簿
書籍目錄
展開
|
闔起
線上使用者
38
人線上 (
12
人在瀏覽
線上書籍
)
會員: 0
訪客: 38
更多…