Ordering strings with and without numbers in 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.
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.
精彩评论