问题排序瑞典字符ÅÄÖMySQL [英] Problem sorting Swedish characters Å Ä Ö MySQL
问题描述
我想根据用户选择,使用asc或desc对列表进行排序。在列表中我有瑞典字符ÅÄÖ,它的问题出现了。我有以下列表:
I'm trying to sort a list with asc or desc - depending on what the user choose. In the list I have the Swedish characters Å Ä Ö and it's here the problem shows up. I have the following list:
(First list)
Stängd
Stängd
Öppen
Krävs ej
Krävs ej
(代表;Stängd= Closed,Öppen=已打开,Krävsej =不需要)
(Standing for; Stängd = Closed, Öppen = Opened, Krävs ej = Not required)
列表应根据用户选择进行排序;
The list should be sorted - depending on what the user choose;
Öppen
Stängd
Stängd
Krävs ej
Krävs ej
或
Krävs ej
Krävs ej
Stängd
Stängd
Öppen
但是现在第一个列表。所以问题是Ö字符。我的数据库和值所在的字段有排序规则utf8_general_ci,所以这是不是问题。
But as it is now the first list is showing up. So the problem is the "Ö" -character. My database and the field that the value is in have the collation utf8_general_ci, so that is'nt the problem. And the character "Ö" is right in both database (looking throu PHPMyAdmin) and output right when printing it out.
我的代码看起来像这样:
My code look like this:
$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = '$sort_by'
AND wposts.post_type = 'sida'
AND wposts.post_status = 'publish'
ORDER BY wpostmeta.meta_value $sort_order";
如何显示,如何解决?
推荐答案
我的数据库和值所在的字段具有排序规则utf8_general_ci,因此是问题
My database and the field that the value is in have the collation utf8_general_ci, so that is'nt the problem
但它是。
utf8_general_ci
将会排序Ö
与 O
。请改用 utf8_swedish_ci
。这将具有正确的排序顺序,其中(IIRC)是ÄAÖ
转到字母表的末尾。
utf8_general_ci
will sort Ö
with O
. Try the utf8_swedish_ci
instead. That will have the correct sorting order, which (IIRC) is that ÄAÖ
go to the end of the alphabet.
有关背景信息,请参阅 9.1.7.8。整理效果的示例
For background info, see 9.1.7.8. Examples of the Effect of Collation
这篇关于问题排序瑞典字符ÅÄÖMySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!