A - Z

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

A - Z

Post by $var »

I have a list of bands that are both alpha and numerically titled. (ie: 63 Monroe, .50)

I am currently sorting them into a-z with this code

Code: Select all

if($_POST["bandletter"]=="")
		{
			$bandletteru="A";
			$bandletterl="a";
		}
		else
		{
			$bandletteru=strtoupper($_POST["bandletter"]);
			$bandletterl=strtolower($_POST["bandletter"]);
		}
and

Code: Select all

<?for($x=65; $x<91; $x++)
		{?>
		<a class="navhover" href="#" onClick="document.nav.bandletter.value='<?=chr($x);?>'; document.nav.submit();">&#<?=$x;?>; </a>
		<?}?>	
		<
But this doesn't display any names starting with a number or other character.
Can this be remedied to list all of them under say... a hash mark for 'misc'?
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Re: A - Z

Post by foobar »

$var wrote: But this doesn't display any names starting with a number or other character.
Can this be remedied to list all of them under say... a hash mark for 'misc'?
Why not use natsort(). I'm not sure how it handles non-alphanumeric characters, but it'll almost certainly put them in some kind of order. Then just split up your array with a foreach loop into groups of the same starting character, unless it's a non-alphanumeric character, in which case you'd just leave all of them in the same group.
Post Reply