iarp Posted December 27, 2008 Share Posted December 27, 2008 Function: <?php function menu($name, $class='') { $uri = $_SERVER['REQUEST_URI']; switch($name){ case 'menu-main': $r = mysql_query("SELECT page_name, page_url FROM " . CONTENT . " WHERE menu_id = 'main' AND page_active = '1'"); while($row = mysql_fetch_array($r, MYSQL_ASSOC)){ echo "<li"; if ($row['page_url'] == $uri) $class .= ' current_page_item'; echo " class=\"" . $class . "\""; echo "><a href=\"" . $this->base() . $row['page_url'] . "\">" . ucfirst($row['page_name']) . "</a></li>\n"; } break; } }?> Page: <?php $cms->menu('menu-main', 'page_item'); ?> Table: TABLE `content` ( `menu_id` varchar(20) NOT NULL default '', `page_name` varchar(255) NOT NULL default '', `page_url` varchar(255) default NULL, ) The site location: http://cms.iarp.ca/ While on the home page, the menu links all contain current_page_item, when you view Haiz, home doesn't but the rest do... and so on as you click each page. I've spent abit trying to figure out what i'm doing wrong and i'm stuck. Help please. The Problem: Only the current page your viewing, should have the current_page_item class. Quote Link to comment https://forums.phpfreaks.com/topic/138582-solved-trying-to-select-an-exact-row/ Share on other sites More sharing options...
wildteen88 Posted December 27, 2008 Share Posted December 27, 2008 Change echo "<li"; if ($row['page_url'] == $uri) $class .= ' current_page_item'; echo " class=\"" . $class . "\""; To echo '<li class="' . $class . (($row['page_url'] == $uri) ? ' current_page_item' : null) . '"'; Quote Link to comment https://forums.phpfreaks.com/topic/138582-solved-trying-to-select-an-exact-row/#findComment-724613 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.