4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 SQL order Problem
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
domuk
WebHelper
WebHelper


Joined: 15 Jan 2004
Posts: 91

PostPosted: Wed Jun 02, 2004 10:56 am (13 years, 5 months ago) Reply with QuoteBack to Top

I am trying to sort my query results into their specific order and have run into a few problems.

I am using the “order by” statement with a mysql database and PHP

1) DATA: 1,2,3,4,5,6,7,8,9,10

Problem: It orders the above data 9,8,7,6,5,4,3,2,10,1 It
looks like the algorithm starts at the first character
in the string orders them and then goes to the
second character.

QUESTION: Is there a way to order the data so it gives
10,9,8,7,6,5,4,3,2,1?


2) I would like to order the list below, but it does not follow any numeric or alphabetical order. There however is an order to the individual letters, which is as below:

M=0
D=1
Vd=2
Ms=3
S=4
Hs=5
Mvs=6
Vs=7

The letters are stored in the database. Is there a way to order these using sql without changing the data stored in the database?

Hope you can help,

Dom.
OfflineView User's ProfileFind all posts by domukSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Wed Jun 02, 2004 3:42 pm (13 years, 5 months ago) Reply with QuoteBack to Top

I don't think there's a solution to the second problem using an SQL command, however there is a solution to the first:

Code:
ORDER BY column ASC
or
Code:
ORDER BY column DESC

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
domuk
WebHelper
WebHelper


Joined: 15 Jan 2004
Posts: 91

PostPosted: Wed Jun 02, 2004 5:29 pm (13 years, 5 months ago) Reply with QuoteBack to Top

Thanks Daniel.

I was using asc and desc.

The problem that I had was the database was set up to varchar when it should be tinyint. it works now.
OfflineView User's ProfileFind all posts by domukSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.067511 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme