|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Sorting 1.1, 1.2, 1.2.1
Hi all..
Need some help here. I am having problem sorting numbers like this: 1.1 1.2 1.2.1 2.0 2.1.1 2.2.1 .... How can i achieve this? FYI, the data are all stored in a character field (can i do it in INT?). Dunno if there already posts like this, if there are please show me where it is. ^^ Thanks in advance |
|
#2
|
|||
|
|||
|
RE: Sorting 1.1, 1.2, 1.2.1
I don't think you'll be able to store it as int or as float with multiple decimals. If you don't have a lot of records yet, the easiest thing would be to break it up and make each number its own field. For example, turn 1.1.1 into three separate fields to store the chapter, section, and sub-section (or whatever you call them).
The next best thing I can offer is a PHP script whereby you explode the term. You can check http://www.php.net/manual/en/function.explode.php for further details on it, but basically it turns the string into an array and divides the term based upon what you tell it to use. If you do $new = explode(".", $old); It will make $new an array based on $old. SO, $new = explode(".", "1.2.3"); will offer $new[0] will = 1 $new[1] will = 2 $new[2] will = 3 You'll probably need to loop through each record in the query result set and then sort the list. I think I'd go with separating them and store each part as a separate field in the database. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Sorting 1.1, 1.2, 1.2.1 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|