ORDER BY question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
LonelyProgrammer
Forum Contributor
Posts: 108
Joined: Sun Oct 12, 2003 7:10 am

ORDER BY question

Post by LonelyProgrammer »

Hi all...

Currently I am doing a quiz database. The questions labelling range from simple (like "1", "2") to rather complex ("1a", "1.1.a" and etc.) so in order to sort the question, I use VARCHAR type as the question number, so that when I use "ORDER BY questionumber" at least "1b" will come after "1a" but not after "2".

The problem is that because of this, question "10" is coming right between "1" and "2" (like when you try to sort files by filename in Windows Explorer). Is there any solution (PHP, or mySQL) around this?

Many thanks in advance!
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

put the sql results into an array in php and use natsort() on the array this should put the results in the order you want
Post Reply