PHP:使用外部数据执行 ORDER BY?
嘿大家!长话短说,如果您不介意向这位 PHP 新手伸出援手的话。 :)
我有一个名为“类别”的数据库字段,其中存储了此内容:
Fruit, People, Place, Animals, Landscape
我在数据库中还有一个单独的表,其中每个项目的字段中都有带有这些类别名称的项目。现在,该脚本(我正在尝试对其进行一点分叉)使用:
SELECT DISTINCT(type), type FROM the_categories ORDER BY type ASC
为了显示所有可用类别的列表。够简单吧?
好吧.....我不想按 ASC 排序,我想按我提到的第一个“类别”字段中的项目列表排序。无论它们的顺序是什么,我想要显示上面的“类型”的顺序。
显然,我必须对逗号进行爆炸,并且可能按照任何顺序给它们一个 1...但即便如此...我如何使用存储在另一个文件夹中的数据进行“orderby”?
这可能吗?哈哈,再次感谢!
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?
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.
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://www.cfdan.com/posts/Handy_MySQL_-_ORDER_BY_FIELD.cfm
http://www.cfdan.com/posts/Handy_MySQL_-_ORDER_BY_FIELD.cfm
这样未来的旁观者就可以得到它......这是爆炸代码
,然后对于查询,只需放入 order 变量
And just so future onlookers have it .... here is the explode code
and then for the query, just put in the the order variable