dskyx46424 2011-05-07 18: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 18: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条)

报告相同问题?