[MySQL] ORDER BY具有固定值 [英] [MySQL] ORDER BY with fixed values

查看:512
本文介绍了[MySQL] ORDER BY具有固定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


我最近遇到了一个奇怪的问题,我对解决方案一无所知。


我尝试做一个订单具有固定数值顺序的BY语句,因为

我的客户想要这样。


我的方法是这样的:


$ the_row ="''A'',''B'','B b'',''C'','D d'',''E'' " ;;


$ q1 = mysql_query(" SELECT DISTINCT foo FROM $ table WHERE bar =

''$ kat_array [$ bart]''订购BY $ the_row")或死(错误时'SELECT''

所有sub_kategorie来自db! - >" .mysql_error());


现在,我得到的不是预期的订单

A

B

B b

C $ / $
D d

E


但类似

A

C

B b

E

D d


结果不反映由$ the_row给出的订单。看来,它b
命令一些元素错了。我尝试了几个变种的查询

但没有任何效果。我也直接在phpMyAdmin中尝试了它与

相同,错误的结果。


所以我的问题是:

这是一个我做错了吗?

这是MySQL查询中的错误,意思是,它不能输出给定的

订单?

我有什么遗漏吗?


我希望有人可以提供帮助。


问候,

Rayden

Hi!

I recently got a strange problem and I have no idea on the solution.

I try to do a ORDER BY statement with a fixed order of values, because
my client want''s it this way.

My approach is like this:

$the_row = "''A'', ''B'', ''B b'', ''C'', ''D d'', ''E''";

$q1 = mysql_query("SELECT DISTINCT foo FROM $table WHERE bar =
''$kat_array[$bart]'' ORDER BY $the_row") or die ("ERROR while ''SELECT''
all sub_kategorie from db! ->".mysql_error());

Now, what I get is not the expected order of
A
B
B b
C
D d
E

but something like
A
C
B b
E
D d

The result is not reflecting the order given by $the_row. It seems, it
orders some elements wrong. I tried several variations of the query
but nothing worked. I also tried it directly in phpMyAdmin with the
same, wrong result.

So my question is:
Is this a mistake done by me?
Is this a mistake in the MySQL query, meaning, it can''t output a given
order?
Did I miss anything?

I hope someone can help.

Regards,
Rayden

推荐答案

the_row ="''A'',''B'',''B b'',''C'',''D d '',''E''" ;;

the_row = "''A'', ''B'', ''B b'', ''C'', ''D d'', ''E''";


q1 = mysql_query(" SELECT DISTINCT foo FROM
q1 = mysql_query("SELECT DISTINCT foo FROM


table WHERE bar =

''
table WHERE bar =
''


这篇关于[MySQL] ORDER BY具有固定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆