:::

7-7 加入分頁功能

  1. 分頁也是 tadtools 內建功能,直接加在 $sql 語法和送出請由之間即可:
    //顯示預設頁面內容
    function list_actions()
    {
        global $xoopsTpl, $xoopsDB, $isAdmin;
    
        $tbl=$xoopsDB->prefix('actions');
    
        $where=$isAdmin?'':"WHERE `enable` = '1'";
    
        $sql="SELECT * FROM `{$tbl}` $where ORDER BY `end_date` DESC";
        
        //getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項);
        $PageBar = getPageBar($sql, 5, 10);
        $bar     = $PageBar['bar'];
        $sql     = $PageBar['sql'];
        $total   = $PageBar['total'];
        $xoopsTpl->assign('bar', $bar);
        $xoopsTpl->assign('total', $total);
    
        $result = $xoopsDB->query($sql) or web_error($sql);
        //取回資料
        $actions=[];
        $myts              = MyTextSanitizer::getInstance();
        while($action=$xoopsDB->fetchArray($result)){
            $action['title']   = $myts->htmlSpecialChars($action['title']);
            $action['content'] = $myts->displayTarea($action['content'], 1, 1, 1, 1, 0);    
            $action['overdue'] = time() > strtotime($action['end_date'])?1:0;
            $actions[]=$action;
        }
    
        $xoopsTpl->assign('actions', $actions);
    
        include_once XOOPS_ROOT_PATH . "/modules/tadtools/sweet_alert.php";
        $sweet_alert = new sweet_alert();
        $sweet_alert->render("delete_action", "admin/main.php?op=delete_action&action_id=", 'action_id');
    }
  2. 得到的 $bar 就是工具列, $total 則是資料總數,我們可以江浙兩個變數送至樣板來使用,故修改 templates/tad_signup_index.tpl,在裡面加入:

    <{if $op=="list_actions"}>
      <h2>活動列表<small>(共 <{$total}> 個活動)</small></h2>
      <table class="table table-bordered table-hover table-striped">
        <tr class="info">
          <th>活動日期</th>
          <th>活動名稱</th>
          <th>截止日期</th>
          <th>功能</th>
        </tr>
        <{foreach from=$actions item=action}>
          <tr>
            <td><{$action.action_date}></td>
            <td>
              <{if $action.enable!=1}>
                <span class="label label-danger">已關閉</span>
              <{/if}>  
    
              <{if $action.overdue}>
                <span class="label label-warning">已過期</span>
              <{/if}> 
              <a href="index.php?action_id=<{$action.action_id}>"><{$action.title}></a>
            </td>
            <td><{$action.end_date}></td>
            <td>
              <{if $isAdmin}>
                <a href="javascript:delete_action(<{$action.action_id}>)" class="btn btn-danger btn-xs">刪除</a>
                <a href="admin/main.php?action_id=<{$action.action_id}>" class="btn btn-warning btn-xs">編輯</a>
              <{/if}>
              <a href="index.php?action_id=<{$action.action_id}>" class="btn btn-info btn-xs">詳情</a>
            </td>
          </tr>
        <{/foreach}>
      </table>
      <{$bar}>
    <{/if}>

     


:::

書籍目錄

展開 | 闔起

http%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D29%26tbdsn%3D894

計數器

今天: 4104410441044104
昨天: 4745474547454745
總計: 7714065771406577140657714065771406577140657714065