由数组值MySQL的排序顺序 [英] MySQL sort order by array value

查看:631
本文介绍了由数组值MySQL的排序顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要运行所在的顺序是由一个数组值确定的MySQL查询。

我的数组是可变的,但数组中的值对应于所谓的'身份证',所以我想在要返回的结果在我的数据库表中的字段的ID顺序9,1,4。

 阵列([0] => 9 [1] => 1 [2] = 1→4)

在MySQL中这是可能或有可能进行排序后,使用数组MySQL的$结果?你可以假设返回的值只有那些在数组中


解决方案

  ORDER BY字段(ID,9,1,4);

<一个href=\"http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_field\">http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_field

I need to run a MySQL query where the order is determined by an array value.

My array is variable but the values in the array correspond to a field in my DB table called 'ID' so I want the result to be returned in the ID order 9, 1, 4.

Array ( [0] => 9 [1] => 1 [2] => 4 )

Is this possible in MySQL or would it be possible to sort the MySQL $result using the array after? You can assume the only values being returned are those in the array.

解决方案

ORDER BY field(id, 9, 1, 4);

http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_field

这篇关于由数组值MySQL的排序顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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