#定義常用變數
$TBL['name']="show_kind";//資料表名稱
$TBL['kind']="slider_home";//分類
```
流程控制
```
//預設動作
default:
$op="op_list";
op_list();
break;
```
3. 後台 slider.php 的 op\_list() ```
########################################
# 列表
########################################
function op_list()
{
global $mysqli,$smarty,$TBL;
#取得所有記錄
$sql = "select *
from `{$TBL['name']}`
where `kind`='{$TBL['kind']}'
order by `sort` ";//die($sql);
$result = $mysqli->query($sql) or die(printf("Error: %s
".$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'] = $row['enable'] ? "是":"否";
$row['target'] = $row['target'] ? "是":"否";
#取得圖片src
$col_name = "slider_home";
$row['file_name'] = get_file_name_src($row['sn'],$col_name);
$rows[]= $row;
}
$smarty->assign("DBV", $rows);
return;
}
```
4. 修改後的 op\_list()
因為在前台,所以要加上 enable='1'
逗點則在第1筆時,$file\_name=空值,所以沒有逗點,
第2筆以後, $file\_name 已有值,所以$comma=","; ```
#函數
########################################
# 列表
########################################
function op_list()
{
global $mysqli,$smarty,$TBL;
#取得所有記錄
$sql = "select *
from `{$TBL['name']}`
where `kind`='{$TBL['kind']}' and `enable`='1'
order by `sort` ";//die($sql);
$result = $mysqli->query($sql) or die(printf("Error: %s
".$sql, $mysqli->sqlstate));
/*
$backstretch_js="
";
*/
$file_name="";
$col_name = "slider_home";
while($row = $result->fetch_assoc())
{
#過濾撈出資料
$row['sn'] = intval($row['sn']);
$comma = $file_name ? ", ":"";
#取得圖片src
$file_name .= $comma. "'" .get_file_name_src($row['sn'],$col_name). "'";
}
$backstretch_js="";
if($file_name){
$backstretch_js="
";
}
$smarty->assign("backstretch_js", $backstretch_js);
return;
}
```
5. 樣板修改 ```
{$backstretch_js}
```
6.