Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old March 31st, 2003, 06:19 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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

Reply With Quote
  #2  
Old April 7th, 2003, 04:03 PM
al042077 al042077 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Omaha, NE
Posts: 23 al042077 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 sec
Reputation Power: 0
Send a message via Yahoo to al042077
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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Sorting 1.1, 1.2, 1.2.1


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT