开发者

Ordering strings with and without numbers in php

开发者 https://www.devze.com 2023-03-04 19:14 出处:网络
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

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:

开发者_如何学Python
  • 32
  • 16
  • 8
  • finals
  • semifinals

Thanks.


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.


rename your finals and semifinals into numbers.

0

精彩评论

暂无评论...
验证码 换一张
取 消