:::
所有書籍
「八小時模組開發」目錄
MarkDown
5-2 my_dict_index.html
1. 開發環境(30分鐘)
2. XOOPS模組基本結構(40分鐘)
2-1 xoops_version.php
3. 建立資料庫(40分鐘)
3-1 xoops_version.php
4. 建立前台搜尋頁面(30分鐘)
4-1 xoops_version.php
4-2 index.php
4-3 my_dict_index.html
5. 建立搜尋表單(40分鐘)
5-1 index.php
5-2 my_dict_index.html
6. 從資料庫撈出資料(40分鐘)
6-1 index.php
6-2 my_dict_index.html
7. 製作後台管理頁(30分鐘)
7-1 index.php
7-2 admin/menu.php
7-3 admin/main.php
7-4 xoops_version.php
7-5 my_dict_adm_main.html
8. 讀出資料並分頁(40分鐘)
8-1 templates/my_dict_adm_main.html
8-2 templates/my_dict_adm_main.html
9. 刪除資料(30分鐘)
10. XOOPS的表單物件(40分鐘)
11. 完成新增功能(30分鐘)
12. 完成編輯功能(40分鐘)
13. XOOPS文字過濾(30分鐘)
6-1 index.php
八小時模組開發 ======= ### 一、從資料庫讀取單筆資料 PHP的寫法: ``` <pre class="brush:php;"> $sql="select cht from `xx_oxford` where `eng`='{$eng}'"; $result=mysql_query($sql) or die(mysql_error()); list($cht)=mysql_fetch_row($result); ``` XOOPS的寫法: ``` <pre class="brush:php;"> $sql="select cht from ".$xoopsDB->prefix("oxford")." where `eng`='{$eng}'"; $result=$xoopsDB->queryF($sql) or redirect_header('index.php', 3, mysql_error()); list($cht)=$xoopsDB->fetchRow($result); $xoopsTpl->assign('eng',$eng); $xoopsTpl->assign('cht',$cht); ``` 1. 因為每個 XOOPS 網站的資料表前置字元都不一樣,故必須用$xoopsDB->prefix("資料表名稱") 的方式來替資料表加上前置字元。 2. 將 $sql 語法送到資料庫執行,可用 $xoopsDB->query($sql) 或者 $xoopsDB->query<span style="color:#FF0000;">F</span>($sql),後者多用在「更新」、「刪除」等地方。 3. 利用 $xoopsDB->fetchRow($result) 可將抓到的結果用數字索引陣列方式傳回,通常可搭配 list() 來將傳回資料指定到變數中。 4. 用 $xoopsDB->fetchArray($result) 則是用文字索引陣列傳回。 5. 利用「$xoopsTpl->assign('樣板標籤名稱' , $變數值);」可將變數送至樣板。 ### 二、套用至樣板 ``` <pre class="brush:xml;"> <{if $eng}> <div class="hero-unit"> <h1><{$eng}></h1> <p><{$cht}></p> </div> <{/if}> ``` 1. 先利用<{if}><{/if}>判斷有無輸入關鍵字 2. 「class="hero-unit"」是BootStrap用來製作醒目區域的一個樣式 3. <{$eng}>或<{$cht}>都是利用「$xoopsTpl->assign('樣板標籤名稱' , $變數值);」從PHP傳來的樣板變數。 ### 三、從資料庫讀取多筆資料 ``` <pre class="brush:php;"> $other=""; $i=1; $sql="select eng,cht from ".$xoopsDB->prefix("oxford")." where `eng` like '{$eng}%'"; $result=$xoopsDB->queryF($sql) or redirect_header('index.php', 3, mysql_error()); while(list($eng,$cht)=$xoopsDB->fetchRow($result)){ $other[$i]['eng']=$eng; $other[$i]['cht']=$cht; $i++; } $xoopsTpl->assign('other',$other); ``` 1. 利用 SQL中「like」的語法,搭配萬用字元「%」,可以用來做模糊搜尋。 2. 「$xoopsDB->fetchRow($result)」一次只會抓回一筆資料,故可以用 while() 迴圈,將所有符合條件的資料全部抓回來 3. 若要套用至樣板迴圈,必須做成陣列形式:「$陣列名稱\[$索引\]\['<span style="color:#FF0000;">樣板標籤</span>'\]=$變數值」 4. 最後,一樣利用「$xoopsTpl->assign('樣板標籤名稱' , $變數值);」將陣列送至樣板。 ### 四、套用至樣板迴圈 ``` <pre class="brush:xml;"> <ol> <{foreach from=$other item=other}> <li><a href="index.php?eng=<{$other.eng}>"><{$other.eng}></a> <{$other.cht}></li> <{/foreach}> </ol> ``` 1. 樣板接收到陣列樣板變數,可以用 <{foreach}><{/foreach}>來拆解之。 2. 「from=$陣列名稱」,from用來接收陣列變數。 3. 「item=<span style="color:#0000FF;">樣板標籤前置字元</span>」,item用來指定迴圈中,樣板標籤的前置字元 4. 迴圈中,若要指定某個陣列值,可用<{$<span style="color:#0000FF;">樣板標籤前置字元</span>**.**<span style="color:#FF0000;">樣板標籤</span>}> 的方式來呈現。
:::
搜尋
search
進階搜尋
QR Code 區塊
快速登入
所有討論區
「PHP全端開發」線上課程討論區
XOOPS使用討論區
一般研習學員
社大學員專用
路過哈啦區
XOOPS佈景設計
XOOPS模組開發
Tad書籍區
即時留言簿
書籍目錄
總目錄
1.開發環境(30分鐘)
2.XOOPS模組基本結構(40分鐘)
2-1xoops_version.php
3.建立資料庫(40分鐘)
3-1xoops_version.php
4.建立前台搜尋頁面(30分鐘)
4-1xoops_version.php
4-2index.php
4-3my_dict_index.html
5.建立搜尋表單(40分鐘)
5-1index.php
5-2my_dict_index.html
6.從資料庫撈出資料(40分鐘)
6-1index.php
6-2my_dict_index.html
7.製作後台管理頁(30分鐘)
7-1index.php
7-2admin/menu.php
7-3admin/main.php
7-4xoops_version.php
7-5my_dict_adm_main.html
8.讀出資料並分頁(40分鐘)
8-1templates/my_dict_adm_main.html
8-2templates/my_dict_adm_main.html
9.刪除資料(30分鐘)
10.XOOPS的表單物件(40分鐘)
11.完成新增功能(30分鐘)
12.完成編輯功能(40分鐘)
13.XOOPS文字過濾(30分鐘)
展開
|
闔起
線上使用者
52
人線上 (
15
人在瀏覽
線上書籍
)
會員: 0
訪客: 52
更多…
:::
主選單
NTPC OpenID
活動報名
模組控制台
進階區塊管理
站長工具箱(急救版)
網站地圖
Tad Tools 工具包
站長工具箱
行事曆
討論留言
嵌入區塊模組
快速登入
網站計數器
好站連結
最新消息
檔案下載
線上書籍
電子相簿
影音播放
常見問題
萬用表單
友站消息
社大學員
新聞
下載
教材
影音
討論
其他選單
好站連結
行事曆
電子相簿
常見問題
萬用表單
即時留言簿
友站消息
社大學員
登入
登入
帳號
密碼
登入