引入TadTools工具
if(!file_exists(XOOPS_ROOT_PATH."/modules/tadtools/tad_function.php")){
redirect_header("http://www.tad0616.net/modules/tad_uploader/index.php?of_cat_sn=50",3, "需要 tadtools 模組,可至<a href='http://www.tad0616.net/modules/tad_uploader/index.php?of_cat_sn=50' target='_blank'>Tad教材網</a>下載。");
}
include_once XOOPS_ROOT_PATH."/modules/tadtools/tad_function.php";
分頁語法(請放在 $sql 之下,$result=$xoopsDB->query($sql); 之前)
//getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項); $PageBar=getPageBar($sql,$num,$page_num); $bar=$PageBar['bar']; $sql=$PageBar['sql']; $total=$PageBar['total'];
//讀出所有資料
function list_dict(){
global $xoopsDB,$xoopsTpl;
if(!file_exists(XOOPS_ROOT_PATH."/modules/tadtools/tad_function.php")){
redirect_header("http://www.tad0616.net/modules/tad_uploader/index.php?of_cat_sn=50",3, "需要 tadtools 模組,可至<a href='http://www.tad0616.net/modules/tad_uploader/index.php?of_cat_sn=50' target='_blank'>Tad教材網</a>下載。");
}
include_once XOOPS_ROOT_PATH."/modules/tadtools/tad_function.php";
//資料庫語法
$sql="select * from `".$xoopsDB->prefix('oxford')."` order by eng";
//getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項);
$PageBar=getPageBar($sql,20,$page_num);
$bar=$PageBar['bar'];
$sql=$PageBar['sql'];
$total=$PageBar['total'];
//將資料庫語法送出執行
$result=$xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
//利用迴圈將所有資料取回
while(list($sn,$eng,$cht)=$xoopsDB->fetchRow($result)){
$dict[$sn]['eng']=$eng;
$dict[$sn]['cht']=$cht;
}
$xoopsTpl->assign("dict",$dict);
$xoopsTpl->assign("bar",$bar);
}
<{$bar}>
<table class="table">
<{foreach from=$dict key=sn item=dict}>
<tr>
<td><{$dict.eng}></td>
<td><{$dict.cht}></td>
<td>
<a href="main.php?op=edit&sn=<{$sn}>" class="btn btn-mini btn-warning">編輯</a>
<a href="main.php?op=del&sn=<{$sn}>" class="btn btn-mini btn-danger">刪除</a>
</td>
</tr>
<{/foreach}>
</table>
<{$bar}>
//判斷目前動作該執行哪一個
switch($op){
//當 $op 的值等於「動作1」時,欲執行的動作
case "動作1":
admin_do_something();
break;
//預設動作
default:
list_dict();
break;
}