Alpha Index don't return accented letters

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
xamonix
Forum Newbie
Posts: 6
Joined: Fri Sep 24, 2010 8:42 am

Alpha Index don't return accented letters

Post by xamonix »

Hi.
I got an alpha index (A | B | C | D |... ) to catalogue lyrics, so if the user wants to list all lyrics starting by "A" he simply clicks "A". But the returned results don't show lyrics started by "À" for example "Às pedras da rua".

How can I get all the results started by "A" including the ones with accented letters like "À"?

Here is the code I got:

Code: Select all

switch($task){
                        case "listforletter":
       
                                $action = "index.php?option=".$option."&Itemid=".$Itemid."&
amp;task=".$task."&letter=".$letter;
                                if($letter!='0')
                                        $database->setQuery("SELECT COUNT(a.id) FROM #__jmovies as a WHERE a.access <= ".(int)$my->gid." AND SUBSTRING(a.title,1,1)='".$letter."'");
                                else
                                        $database->setQuery("SELECT COUNT(a.id) FROM #__jmovies as a WHERE a.access <= ".(int)$my->gid." AND (SUBSTRING(a.title,1,1)='0'");
                                $total = $database->loadResult();
                                break;

Thank you for your time !
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: Alpha Index don't return accented letters

Post by tr0gd0rr »

It depends on the character set used on the column. You are probably using latin1. You'll need to use utf8_general_ci (Source). And you may need to use `LIKE '$letter%'` instead of `SUBSTRING()`.
In general, you should probably use utf8_general_ci on all string-type columns.
Post Reply