Jump to content

[SOLVED] Trying to select an exact row


iarp

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/138582-solved-trying-to-select-an-exact-row/
Share on other sites

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) . '"';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.