Title1

Title2

Title3

12-6 op_list

程式:op_list


#################################
# 列表程式
#
#################################
function op_list() {
	global $mysqli, $smarty;

	#取得所有記錄
	$sql = "select *
          from `creative_nav`
          where `kind`='nav_home'
          order by `sort` "; //die($sql);

	$result = $mysqli->query($sql) or die(printf("Error: %s <br>" . $sql, $mysqli->sqlstate));

	$rows = array();
	while ($row = $result->fetch_assoc()) {
		#過濾撈出資料
		$row['sn'] = intval($row['sn']);
		//http://www.w3school.com.cn/php/func_string_htmlspecialchars.asp
		$row['title'] = htmlspecialchars($row['title'], ENT_QUOTES); // 轉換雙引號和單引號
		$row['url'] = htmlspecialchars($row['url'], ENT_QUOTES); // 轉換雙引號和單引號
		$row['sort'] = intval($row['sort']);
		$row['enable'] = intval($row['enable']);
		$row['target'] = intval($row['target']);

		$rows[] = $row;
	}

	$smarty->assign("rows", $rows);
	return;
}

樣板 op_list

<{if $op == "op_list"}>
  <div class="panel panel-default">
    <div class="panel-heading">選單管理 - 列表</div>
    <!-- /.panel-heading -->
    <div class="panel-body">
      <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover">
          <thead>
            <tr class="active">   
              <th class="col-md-3 text-center">標題</th>
              <th class="col-md-3 text-center">網址</th>
              <th class="col-md-1 text-center">外連</th>
              <th class="col-md-1 text-center">狀態</th>
              <th class="col-md-1 text-center"><a href="?op=op_form" class="btn btn-xs btn-primary">新增</a></th>
            </tr>
          </thead>
          <tbody>
            <{foreach from=$rows item=row}>
              <tr>
                <td class="text-center"><{$row.title}></td>
                <td><{$row.url}></td>
                <td class="text-center">
                  <{if $row.target == 1}>
                    <img src="<{$smarty.const.WEB_URL}>/images/yes.gif">
                  <{else}>
                    <img src="<{$smarty.const.WEB_URL}>/images/no.gif">
                  <{/if}>
                </td>
                <td class="text-center">
                  <{if $row.enable == 1}>
                    <img src="<{$smarty.const.WEB_URL}>/images/yes.gif">
                  <{else}>
                    <img src="<{$smarty.const.WEB_URL}>/images/no.gif">
                  <{/if}> 
                </td>
                <td class="text-center">                    
                  <a href="?op=op_form&sn=<{$row.sn}>" class="btn btn-xs btn-success">
                    編輯
                  </a>
                  <a href="javascript:op_delete_js(<{$row.sn}>);" class="btn btn-xs btn-danger">
                    刪除
                  </a>
                </td>
              </tr> 
            <{/foreach}>
                              
          </tbody>
        </table>
      </div>
      <!-- /.table-responsive --> 
    </div>
    <!-- /.panel-body -->
  </div>
<{/if}>