dtvp3625 2014-09-14 17:21
浏览 25
已采纳

如何以自定义顺序从mysql数据库中回送获取的数组数据? [关闭]

I have been trying to print out data from a database table in custom order like for example.. I have a table and that have alot rows and have one column as listing_type which have values like Gold,Premium,Silver,Free etc for each row..! so how I would be able to print the data from fetched array in order like at first it should echo all Gold and then Premium and then Silver and then Free etc like..!

Any help would be appreciated..Thanks waiting for your reply.!

  • 写回答

2条回答 默认 最新

  • dpj83664 2014-09-14 17:25
    关注

    Use an ORDER BY clause in your MySQL query like this:

    SELECT * 
    FROM `table` 
    ORDER BY FIELD(`listing_type`, 'Gold', 'Premium', 'Silver', 'Free')
    

    The MySQL function FIELD() returns the position of str in the given strings. With this, you can create a custom order to sort your results on.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题