:::

6-6 顯示列表

一、列出所有活動

  1. 列出所有活動時,先做個基本篩選,篩選出:
    • 有啟用(enable=1)的活動
    • 截止日期還沒到的活動理論上過其還是要能顯示,只是不能報名
  2. 此外,排序時,希望以快到截止日的活動優先呈現,故以截止日來做反降冪排序。
  3. 整個語法如下:
    //顯示活動列表
    function list_action()
    {
        global $xoopsDB, $xoopsTpl;
    
        $tbl    = $xoopsDB->prefix('actions');
        $sql    = "SELECT * FROM `{$tbl}` WHERE `enable` ='1' ORDER BY `end_date` DESC";
        $result = $xoopsDB->query($sql) or web_error($sql);
        while ($action = $xoopsDB->fetchArray($result)) {
            $actions[] = $action;
        }
        $xoopsTpl->assign('actions', $actions);
    }

二、修改 tad_signup_index.tpl 樣板檔

  1. 編輯 templates/tad_signup_index.tpl,加入以下語法:
    <{if $op=="list_action"}>
      <h2>所有活動列表</h2>
      <table class="table table-bordered table-hover table-striped">
        <thead>
          <tr class="info">
            <th>活動名稱</th>
            <th>活動日期</th>
            <th>報名截止日</th>
            <th>功能</th>
          </tr>
        </thead>
        <tbody>
        <{foreach from=$actions item=action}>
          <tr>
            <td><a href="index.php?action_id=<{$action.action_id}>"><{$action.title}></a></td>
            <td><{$action.action_date}></td>
            <td><{$action.end_date}></td>
            <td>
              <a href="index.php?action_id=<{$action.action_id}>" class="btn btn-info btn-xs">詳情</a>
            </td>
          </tr>
        <{foreachelse}>
          <tr>
            <td colspan=4>暫無活動</td>
          </tr>
        <{/foreach}>
        </tbody>
      </table>
    <{/if}>

     


:::

書籍目錄

展開 | 闔起

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

計數器

今天: 1423142314231423
昨天: 3438343834383438
總計: 7391752739175273917527391752739175273917527391752