Jump to content

help with array and loop


samoht

Recommended Posts

hello again,

 

ok I am making progress but still not coming up with the right solution. I have a horizontal nav bar that has drop down navigation - the drop down navigation is populated from my database based on the user the list will be different. Meaning I have 1 table that stores the navigation links (called sanavbars) and another that stores the users (called sauser) and then a 3rd table that stores which links from sanavbars each user has access to.

 

Now I want to change the class of the horizontal nav bar which contains the current page (e.g. basename($_SERVER['SCRIPT_NAME'])) in one of its sub navigation links.

 

My horizontal nav has 5 tabs.

 

right now this is what I have:

<?php
$page = basename($_SERVER['SCRIPT_NAME']);
$NavBarsExist = false;
mysql_select_db($database_connection1, $connection1);
$query_rsSANavBars = "SELECT * FROM sanavbars WHERE Type = 'SA' AND FlagStatus = 'A' ORDER BY Name";
$rsSANavBars = mysql_query($query_rsSANavBars, $connection1) or die(mysql_error());
$row_rsSANavBars = mysql_fetch_assoc($rsSANavBars);
$totalRows_rsSANavBars = mysql_num_rows($rsSANavBars);

if ($totalRows_rsSANavBars > 0) {
while ($row = mysql_fetch_assoc($rsSANavBars)) {
			 $linkurls[] = $row['LinkURL']; // add new array element to $linkurls, an array
		 if ($row['LinkURL'] == $page) {
    	 $currentType = $row['Type'];
  		 }

}

 		// Now, if $currentType is set, then there was a match with $page
		if($currentType == 'SA'){$c = 'current';}else{$c = 'adminnav';}
 		//$c = $cl ? $c = 'current' : 'adminnav';
 		echo '<ul class="' .$c . ' one"><li><a href="#?current=one&sub=none"><b>Secure Access</b><!--[if IE 7]><!--></a><!--<![endif]-->'."\n";
	 	echo '<!--[if lte IE 6]><table><tr><td><![endif]-->'."\n";
	 	echo '<ul class="sub" id="navlight">'."\n";
	do {
		$SANavBarId = $row_rsSANavBars['NavBarId'];
		mysql_select_db($database_connection1, $connection1);
		$query_rsSAUserNavBars = "SELECT * FROM sausernavbars WHERE SAUserId = '$SAUserId' AND SANavBarId = '$SANavBarId' AND FlagStatus = 'A'";
		$rsSAUserNavBars = mysql_query($query_rsSAUserNavBars, $connection1) or die(mysql_error());
		$row_rsSAUserNavBars = mysql_fetch_assoc($rsSAUserNavBars);
		$totalRows_rsSAUserNavBars = mysql_num_rows($rsSAUserNavBars);

		// show navbar if user has access to it
		if ($totalRows_rsSAUserNavBars != 0 || ($totalRows_rsCheckEmpty == 0 && $row_rsSANavBars['NavBarId'] == '112')) {
			$NavBarsExist = true; ?>
			<li><a href="<?php echo $row_rsSANavBars['LinkURL'] ?>" class="blackRed"><?php echo $row_rsSANavBars['Name']; ?></a></li>
<?php
		}
	} while ($row_rsSANavBars = mysql_fetch_assoc($rsSANavBars));
}
if ($totalRows_rsSANavBars == 0 || !$NavBarsExist)
	echo '<li><a href="#">not available</a></li>'; ?>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
</ul>

for each of the five tabs. The problem with this code is that it only returns one link for the sub nav?

 

Any ideas?

 

Thanks for the help.

Link to comment
Share on other sites

try[ode]<?php
$page = basename($_SERVER['SCRIPT_NAME']);
$NavBarsExist = false;
mysql_select_db($database_connection1, $connection1);
$query_rsSANavBars = "SELECT * FROM sanavbars WHERE Type = 'SA' AND FlagStatus = 'A' ORDER BY Name";
$rsSANavBars = mysql_query($query_rsSANavBars, $connection1) or die(mysql_error());
//$row_rsSANavBars = mysql_fetch_assoc($rsSANavBars);
$totalRows_rsSANavBars = mysql_num_rows($rsSANavBars);

if ($totalRows_rsSANavBars > 0) {
while ($row = mysql_fetch_assoc($rsSANavBars)) {
			 $linkurls[] = $row['LinkURL']; // add new array element to $linkurls, an array
		 if ($row['LinkURL'] == $page) {
    	 $currentType = $row['Type'];
  		 }

}

 		// Now, if $currentType is set, then there was a match with $page
		if($currentType == 'SA'){$c = 'current';}else{$c = 'adminnav';}
 		//$c = $cl ? $c = 'current' : 'adminnav';
 		echo '<ul class="' .$c . ' one"><li><a href="#?current=one&sub=none"><b>Secure Access</b><!--[if IE 7]><!--></a><!--<![endif]-->'."\n";
	 	echo '<!--[if lte IE 6]><table><tr><td><![endif]-->'."\n";
	 	echo '<ul class="sub" id="navlight">'."\n";
	 mysql_data_seek($rsSANavBars,0);
	while ($row_rsSANavBars = mysql_fetch_assoc($rsSANavBars)) {
		$SANavBarId = $row_rsSANavBars['NavBarId'];
		mysql_select_db($database_connection1, $connection1);
		$query_rsSAUserNavBars = "SELECT * FROM sausernavbars WHERE SAUserId = '$SAUserId' AND SANavBarId = '$SANavBarId' AND FlagStatus = 'A'";
		$rsSAUserNavBars = mysql_query($query_rsSAUserNavBars, $connection1) or die(mysql_error());
		$row_rsSAUserNavBars = mysql_fetch_assoc($rsSAUserNavBars);
		$totalRows_rsSAUserNavBars = mysql_num_rows($rsSAUserNavBars);

		// show navbar if user has access to it
		if ($totalRows_rsSAUserNavBars != 0 || ($totalRows_rsCheckEmpty == 0 && $row_rsSANavBars['NavBarId'] == '112')) {
			$NavBarsExist = true; ?>
			<li><a href="<?php echo $row_rsSANavBars['LinkURL'] ?>" class="blackRed"><?php echo $row_rsSANavBars['Name']; ?></a></li>
<?php
		}
	} 
}
if ($totalRows_rsSANavBars == 0 || !$NavBarsExist)
	echo '<li><a href="#">not available</a></li>'; ?>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
</ul>

Link to comment
Share on other sites

Thanks for the help!

 

I now have one more issue. I want to keep the main tab current if the user navigates inside the pages available under that tab. (e.g. sauser.php is a sub link under the "Secure Access" tab. once there a user can navigate to sauseredit.php or sauserview.php  - fortunately the new pages will always start with the same base page in there names - so if I could check for what ever comes before the .php and then test to see if that starts the name of the new page navigated too then I could keep the proper tab current)

 

hopefullly that all makes sense.

 

Any ideas?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.