突出显示DYnamic导航PHP Mysql上的当前页面

时间:2014-01-06 21:24:17

标签: php html mysql css content-management-system

我从数据库中获取动态导航菜单,因为我有一个CMS,所以这是我的代码:

<ul>
<?php
$result = mysql_query("SELECT id, name, DESCRIPTION FROM menu where VISIBLE='1' ORDER BY `order` ASC") or die(mysql_error());                   
while($row = mysql_fetch_array($result)){
printf('<li>%s %s </a></li> ', $row['name'],$row['DESCRIPTION']);
}
?>

我必须在li元素中添加它。此代码也应来自数据库

<?php if (strpos($_SERVER['PHP_SELF'], 'index.php')) echo 'class="current"';?>

我该怎么做?提前谢谢。

1 个答案:

答案 0 :(得分:0)

也许是这样的:

<ul>
<?php
$result = mysql_query("SELECT id, name, DESCRIPTION 
FROM menu where VISIBLE='1' ORDER BY `order` ASC") 
or die(mysql_error());                   
while($row = mysql_fetch_array($result)){
if (strpos($_SERVER['PHP_SELF'], 'index.php')) $code = 'class="current"'; else $code = '';
printf('<li %s>%s %s </a></li> ', $code, $row['name'],$row['DESCRIPTION']);
}
?>