I have a menu generated in php this way.
<?php
while($rowMenu = mysql_fetch_array($rsMenu)){
$link="category.php?cat=".$rowMenu['MenuItemID'];
$name = utf8_encode($rowMenu['name']);
?>
<a href="<?php echo $link; ?>"><li><?php echo $name; ?></li></a>
<?php
}
?>
and now I want to add a background-color to the item of the present page.The background-color is defined in css ( .productActive )
I search for add a css class in php like I make with javascript but didnt find any solution, so I made this way
<?php
$cat=$_GET['cat']; /gets the id from the URL
while($rowMenu = mysql_fetch_array($rsMenu)){
$link="category.php?cat=".$rowMenu['MenuItemID'];
$name = utf8_encode($rowMenu['name']);
?>
<a href="<?php echo $link; ?>"><li><?php echo $name; ?></li></a>
<?php
if($cat == $rowMenu['MenuItemID']) {
echo"<a href=".$link."><li class='productActive'>".$nome."</li></a>";
}
}//end of while
?>
But this way add one more item to the menu. it repeats the present li item. Is there any other way??
Thanks
That should work, I think