gpt4 book ai didi

mysql - 瑞典语字符排序问题 Å Ä Ö MySQL

转载 作者:IT王子 更新时间:2023-10-28 23:45:25 31 4
gpt4 key购买 nike

我正在尝试使用 asc 或 desc 对列表进行排序 - 取决于用户的选择。在列表中,我有瑞典语字符 Å Ä Ö,问题就在这里出现。我有以下列表:

(First list)
Stängd
Stängd
Öppen
Krävs ej
Krävs ej

(代表;Stängd = 封闭,Öppen = 开放,Krävs ej = 不需要)

列表应该排序——取决于用户的选择;

Öppen
Stängd
Stängd
Krävs ej
Krävs ej

Krävs ej 
Krävs ej
Stängd
Stängd
Öppen

但是现在第一个列表出现了。所以问题是“Ö”-character。我的数据库和值所在的字段具有归类 utf8_general_ci,所以这不是问题所在。并且字符“Ö”在数据库中(通过 PHPMyAdmin 查找)和打印时输出都是正确的。

我的代码是这样的:

$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";

这怎么会出现,我该如何解决?

最佳答案

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Ö 到字母表的末尾。

有关背景信息,请参阅 9.1.7.8. Examples of the Effect of Collation

关于mysql - 瑞典语字符排序问题 Å Ä Ö MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5529013/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com