Solved

PHP function not sorting from A-Z across the menu for the links in my pages

Posted on 2008-06-14
2
162 Views
Last Modified: 2011-10-19
Hi guys hope u are well and can assist.

I have the following function which grabs a list of filenames and creates links out of them to build a menu system.
The problem I have as you can see in the screen dump is that the links are not being displayed alphabetically eg.A - Z from left to right.
For example, in row 2, "auditing" is seen way to the right when it should be where "hware" is.

If someone can help me with the below function, which I think is causing this, through not having a sorting facility, id very much appreciate it.
Thank you.


In my php pages, the function gets called as follows....

<div id="menu2_div">
      <ul id="menu2_ul">
            <?php echo menu2_navlinks($menu2_pages, $menu2_current_page); ?>                
      </ul>      
</div>

function menu2_navlinks($menu2_pages, $menu2_current_page){
	foreach ($menu2_pages as $menu2_pagename=>$url) {
//$menu2_navlinks = '';
 
						/*	............................................................
							Test to see if the link's url is the same as the current 
							page variable against the current page.
							If they're the same - set the class to current_link
							..........................................................*/	
							
		if	($url==$menu2_current_page){
			$menu2_class='menu2_current_link';
			$menu2_style="<span class=\"$menu2_class\">";
			$menu2_end_style='</span>'; 
		}	
		else {  //otherwise leave the class blank
				$menu2_style='';
				$menu2_end_style='';
		}						 
						/*	............................................................
							As the loop runs, it will add each link based on whether or 
							not it's the current page
							..........................................................*/	
										
		$menu2_navlinks.="<li>$menu2_style<a href=\"$url\">$menu2_pagename</a>$menu2_end_style  | </li>\n";
	}
	return $menu2_navlinks;
	
							// End the function ... 		
}

Open in new window

links-in-menu2-not-sorted-A-Z-le.bmp
0
Comment
Question by:Simon336697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21785877
before:
foreach ($menu2_pages as $menu2_pagename=>$url) {
put this line (will sort by the url:
asort($menu2_pages);
or this (will sort by page name):
ksort($menu2_pages);
0
 
LVL 1

Author Comment

by:Simon336697
ID: 21787303
Hi angellll,

asort works!!!!!

Thank you mate...champion as always.

S
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question