網站程式設計-PHP
- 前台nav.php,前台只要撈出 enable='1'
<?php
#取得所有啟用的記錄
$sql = "select *
from `show_kind`
where `kind`='nav_home' and `enable`='1'
order by `sort` ";
$mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate));
$result = $mysqli->query($sql);
$nav_body="";
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['target'] = $row['target'] ? " target='_blank'":"";
$nav_body .= "<li><a href='{$row['url']}'{$row['target']}>{$row['title']}</a></li>";
}
$nav="
<!--導覽列 start-->
<nav class='navbar navbar-default' role='navigation' style='margin-bottom:0;'>
<div class='container'>
<!-- Brand and toggle get grouped for better mobile display -->
<div class='navbar-header'>
<button type='button' class='navbar-toggle collapsed' data-toggle='collapse' data-target='#bs-example-navbar-collapse-1'>
<span class='sr-only'>Toggle navigation</span>
<span class='icon-bar'></span>
<span class='icon-bar'></span>
<span class='icon-bar'></span>
</button>
<a class='navbar-brand' href='index.php'>{$WEB['title']}</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class='collapse navbar-collapse' id='bs-example-navbar-collapse-1'>
<ul class='nav navbar-nav navbar-right'>
{$nav_body}
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav><!-- /.nav -->
";
#將變數送至樣版引擎
$smarty->assign("nav" , $nav);
-