#撈出選單 nav_home(); ################################# # 撈出選單 # ################################# function nav_home() { global $mysqli, $smarty; #取得所有記錄 $sql = "select * from `creative_nav` where `kind`='nav_home' and `enable`='1' 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'] = intval($row['enable']); $row['target'] = intval($row['target']); $rows[] = $row; } $smarty->assign("nav_home", $rows); return; } ``` 三、樣板處理 1. templates/default/tpl/creative\_nav.html 程式端:$smarty->assign("nav\_home", $rows); ``` Toggle navigation Menu <{$WEB.title}> <{foreach from=$nav_home item=row key=k}> target="_blank"<{/if}>><{$row.title}> <{/foreach}> ```
Toggle navigation Menu <{$WEB.title}> <{foreach from=$nav_home item=row key=k}> target="_blank"<{/if}>><{$row.title}> <{/foreach}> ```