:::
6-6 顯示列表
一、列出所有活動
- 列出所有活動時,先做個基本篩選,篩選出:
- 有啟用(enable=1)的活動
- 截止日期還沒到的活動理論上過其還是要能顯示,只是不能報名
- 此外,排序時,希望以快到截止日的活動優先呈現,故以截止日來做反降冪排序。
- 整個語法如下:
//顯示活動列表 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 樣板檔
- 編輯 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}>
6-5 陣列傳至Smarty樣板的用法