PHP:使用外部数据进行订购吗? [英] PHP: do an ORDER BY using external data?

查看:44
本文介绍了PHP:使用外部数据进行订购吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!长话短说,如果您不介意向这个新手PHPer伸出援手的话. :)

Ahoy all! Long story short with this one if you don't mind lending a hand to this novice PHPer. :)

我有一个名为类别"的数据库字段,其中存储了以下内容:

I have a database field called "Categories" that has this stored:

Fruit, People, Place, Animals, Landscape

我在数据库中还有一个单独的表,其中每个项目的字段中都有具有这些类别名称的项目.现在,该脚本(我想稍微介绍一下)使用:

I also have a separate table in the DB that has items with these category names in the fields for each item. Right now, the script (i am trying to fork it a bit) uses:

SELECT DISTINCT(type), type FROM the_categories ORDER BY type ASC 

以显示所有可用类别的列表.很简单吧?

in order to display a list of all categories available. Simple enough right?

Wellllllll .....我不想按ASC排序,我想按我提到的第一个Categories字段中的项目列表进行排序.无论这些顺序是我要在上面显示类型"的顺序.

Welllllll..... I don't want to sort by ASC, I want to sort by the list of items in the first Categories field I mentioned. Whatever order those are in is the order I want to display the "types" above.

很显然,我必须对逗号进行爆炸,并且可能给它们一个1的顺序....但是即使那样....我如何使用存储在另一个文件夹中的数据执行"orderby"操作?

Obviously I will have to do an explode on the commas, and maybe give them a 1 to whatever order....but even then.... how do I do an "orderby" using data stored in another folder?

这甚至有可能吗?大声笑再次感谢!

Is this even possible? lol Thanks again!

推荐答案

... ORDER BY FIELD(type,"Fruit","People","Place","Animals","Landscape")

http://www.cfdan.com/posts/Handy_MySQL_-_ORDER_BY_FIELD.cfm

这篇关于PHP:使用外部数据进行订购吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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