Jump to content


Block words


4 replies to this topic

#1 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 20 August 2006 - 07:25 AM

I mean, when selecting from the database, and ordering by the title of things.
So that it goes like
Allen
alex
benny
brad
frank
george
lenny
paul
tim
theresa
thimble
zoe


Okay, that's what it does currently.
but if you put "the aaa" and "the bbb"
it would end up like this

Allen
alex
benny
brad
frank
george
lenny
paul
tim
the aaa
the bbb
theresa
thimble
zoe


I want it to do like this
the aaa
Allen
alex
the bbb
benny
brad
frank
george
lenny
paul
tim
theresa
thimble
zoe

I've searched this, messed with this, couldn' figure it, couldn't find it anywhere. I'm stuck.
I need major help on doing this, thanks.

#2 Wolfe

    Young Padawan

  • Members
  • Pip
  • 102 posts
  • Gender:Male
  • Location:Louisiana

Posted 20 August 2006 - 08:58 AM

I'm assuming you're using PHP/MySQL to do this, in which case, MySQL doesn't have a built-in feature of alphabetizing without the "the." It would be nice if it did.

Which means, the only way you're going to have to pull all the database values and use php to alphabetize them yourself.

You could also just add the names with "the" in the title like this:

aaa, the
bbb, the

Instead of how you were doing it.

Unless you're deadset on showing them the way they are there, I suggest the easy way out :P

Edited by Wolfe, 20 August 2006 - 08:58 AM.


#3 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 20 August 2006 - 09:58 AM

you would have to get the info from mysql and put it into an array (hehe... ironic?) then use sort() to display it... i'll look into it and see if i can come up with something

or maybe someone will reply before i even get started?!

Edited by coolaid, 20 August 2006 - 09:58 AM.


#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 20 August 2006 - 11:04 AM

function replaceThe($string){
	$string = str_replace('the ', '', $string);
	return str_replace('The ', '', $string);
}

$array = array_map('replaceThe', $results);
array_multisort($array, SORT_ASC, SORT_STRING, $results);

print_r($results);
Idea stolen from php.net (again). If it doesn't work, it's not my fault, i haven't tested it. It should work though.

Edited by rc69, 20 August 2006 - 11:04 AM.


#5 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 21 August 2006 - 12:11 AM

I've got one word to say, and it's not good.
Thanks for that though, i'll see if I can get it figured out. XD





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users