FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Sort using utf characters in mysql or php ? best solutions...
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Sort using utf characters in mysql or php ? best solutions... [message #172818] Fri, 04 March 2011 00:58 Go to previous message
SM is currently offline  SM
Messages: 3
Registered: March 2011
Karma:
Junior Member
Hello,
Using MySQL, i'm selecting a list of songs in spanish that i would
like to sort. Here's a list of names that is returned by the query:

¡Decirevilla!
Alhambra
123 pasitos
África
Arroz
Decir

The sorted list should look like this:

123 pasitos
África
Alhambra
Arroz
¡Decirevilla!
Decir


After all of the research i've read, i've concluded that there is no
reasonable way to achieve this using MySQL. I've tried collation,
charset, etc... but there is no way the character ¡, ?, etc... can by
sorted accordingly to my desired result. Even the Á is not sorted the
way i want to...

Question 1: Is this a reasonable conclusion?

I believe the only way to achieve this is by passing the results to an
array in php and then sort the array using a custom function... all
this using the function usort (need to sort by value and i don't care
about maintaning the key association). Something similar to this:


function normalize($a, $b) {
if ($a == $b) {
return 0;
}

return ($a < $b) ? -1 : 1;
}


$tracks = array();

while ($row = $result->fetch_assoc()) {
$tracks[] = $row;
}

usort($tracks, 'normalize');


Question 2: Is this the best way to achieve a custom sorting?


Here's where i'm hitting a wall:

Question 3: I have no idea how to create the normalize function to
sort the names accordingly to my needs. How do i ignore certain
characters (¡, ?, ', !, ¿) and how do i replace other characters with
the natural equivalent (Á -> A, É -> E, etc..)
I believe that by ignoring certain characters and replacing others, i
can achieve the sorting i'm loojing for...

Question 4: All this make sense? Am i on the right path?


Thanks in advance for all your advice.
Marco
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Want to free hosting
Next Topic: [ANN]VTD-XML 2.10
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 14:49:31 GMT 2024

Total time taken to generate the page: 0.11985 seconds