dskyx46424 2011-05-07 10:14
浏览 44
已采纳

在php中使用和不使用数字排序字符串

Hey, I'm having a sorting issue. I have the rows:

  • 32
  • 16
  • 8
  • semifinals
  • finals

that i need to be sorted like that. The problem is they don't always appear in that order. Right now I'm using: ORDER BY ABS(roundOf) DESC and it's comming out:

  • 32
  • 16
  • 8
  • finals
  • semifinals

Thanks.

  • 写回答

2条回答 默认 最新

  • drcb19700 2011-05-07 10:19
    关注

    There is no way to do this without storing an order number with that data. The words semifinals and finals do not hold any order data comparable to the numbers of course. Store this in an array in the order you need it or if it's stored in a relational db, use an order column.

    Possible db table:

    order | name   | numberOfPlayers
    
    1     | finals |     2 
    2     | semis  |     4 
    ...
    

    Array:

    $rounds = array[1] = 'finals';
    

    etc.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部