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 September 5th, 2002, 05:23 PM
Gipz Gipz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 98 Gipz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Gipz
MySQL, order by

I'm trying to sort a field and find it coming out like this:
Vol 1
Vol 10
Vol 11
Vol 12
Vol 2
Vol 3
Vol 4


Is there a way to get the rows in "correct" order? This is how I want it:
Vol 1
Vol 2
Vol 3
Vol 4
[...]
Vol 10
Vol 11
Vol 12

Btw, I'm using the "ORDER BY title" syntax.

Reply With Quote
  #2  
Old September 5th, 2002, 05:41 PM
Gipz Gipz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 98 Gipz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Gipz
RE: MySQL, order by

In that example the fields only contains numbers. For me this isn't the case so I don't think that will work.

Reply With Quote
  #3  
Old September 5th, 2002, 06:59 PM
Nimco Nimco is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 132 Nimco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to Nimco
RE: MySQL, order by

Can you not remove the 'Vol' part of the data from each row? Ideally you should never repeat information in each row if it is always the same since it can be prefixed later.

There's probably a really easy way of modifying this. If not, you could try something along the lines of:

Explode each field
Sort by number
Recompile field

Reply With Quote
  #4  
Old September 5th, 2002, 07:03 PM
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
RE: MySQL, order by

If you intend on keeping the "vol" part of the string then try labeling them as "vol 001", "vol 002", etc. Or if you do not intend on surpassing volume 999 then just use one leading zero (ex. vol 01) This should sort correctly.

Reply With Quote
  #5  
Old September 5th, 2002, 07:11 PM
Gipz Gipz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 98 Gipz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Gipz
RE: MySQL, order by

Thanks everyone for the help...

The field that I'm sorting contains movietitles. Most titles doesn't contain numbers. But the problems ocurrs when it comes to the "Friends" episodes.

It's a swedish site but you can have a look at:
http://www.prontofilm.com/list.php?c=2&p=9

Reply With Quote
  #6  
Old September 5th, 2002, 07:34 PM
Nimco Nimco is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 132 Nimco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to Nimco
RE: MySQL, order by

You could try something along the lines of using eregi() to sort out the numbers in a title then sort by that and apply to the array.

Reply With Quote
  #7  
Old September 19th, 2002, 12:49 AM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to postalcow
RE: MySQL, order by

Why not do it the easy way.
01
02
03
..
10

The leading zero wil put it in order.

Reply With Quote
  #8  
Old October 9th, 2002, 10:01 PM
LordBlink LordBlink is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Buffalo, NY
Posts: 1 LordBlink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: MySQL, order by

The problem is that the `Vol` column is being sorted as a character string. So what you need to do it order it as a number as stated above. When you cast things from strings to ints in MySQL, it will read all leading numbers and count that as the new numeric value, ie. 12val would become 12, 123asdf12 would become 123 and so on.
Now you can see that there will be a problem with your strings as they start with Vol and not numbers. What you will need to do is to use a string function to remove the leading part. SUBSTRING should be able to do exactly what you want, or SUSTRING(column,5) will return just the numeric part. However it returns that value as a string, so now we will have to cast it to an integer as stated above, which will give you a final query of:

SELECT * FROM table ORDER BY SUBSTRING(column,5)+0;

Keep in mind that query can't use an index to order by, so it won't be very fast for large data sets. You would definately want to consider going with the idea as given by codegirl with the seperate volume number.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > MySQL, order by


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 3 hosted by Hostway
Stay green...Green IT