Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6673069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:35:03+00:00 2026-05-26T03:35:03+00:00

I have a list of data from SQL field. I want to sort by

  • 0

I have a list of data from SQL field. I want to sort by the field ASC but when i do it comes up in the wrong order. I know why it does it, but wondered if there was a solution around this problem. Ive heard of natsort php function, but not investigated it. Is there an easy way?

Academy

Under 10′s Blue

Under 10′s Green

Under 11′s Red

Under 11′s White

Under 13′s Blue

Under 13′s Red

Under 13′s White

Under 14′s Blue

Under 15′s Blue

Under 15′s Red

Under 15′s White

Under 16′s Red

Under 18′s Blue

Under 18′s Red

Under 7′s

Under 8′s Red

Under 9′s Red

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:35:04+00:00Added an answer on May 26, 2026 at 3:35 am

    There is a very simple approach to sort this list. For all values of Academy starting with Under you perform the sort algorithm based on the following ORDER BY clause:

    ORDER BY
    REPLACE(Academy,'Under ','') + 0,Academy
    

    The first sort column is based on removing the string ‘Under ‘ and then adding 0. This will force an ordering of the resulting integer.

    Here is an example of computing the numeric value by removing ‘Under ‘ first:

    mysql> select REPLACE('Under 15\'s Red','Under ','') + 0;
    +--------------------------------------------+
    | REPLACE('Under 15\'s Red','Under ','') + 0 |
    +--------------------------------------------+
    |                                         15 |
    +--------------------------------------------+
    1 row in set (0.00 sec)
    

    The second sort column will order by the string value of Academy. All 'Under 15's' are grouped together and alphanumerically sorted.

    Here is your sample data from the question loaded into a table and sorted:

    mysql> use test
    Database changed
    mysql> drop table if exists under99color;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> create table under99color
        -> (academy varchar(30),
        -> id int not null auto_increment,
        -> primary key (id),
        -> index academy (academy)) engine=MyISAM;
    Query OK, 0 rows affected (0.04 sec)
    
    mysql> show create table under99color\G
    *************************** 1. row ***************************
           Table: under99color
    Create Table: CREATE TABLE `under99color` (
      `academy` varchar(30) DEFAULT NULL,
      `id` int(11) NOT NULL AUTO_INCREMENT,
      PRIMARY KEY (`id`),
      KEY `academy` (`academy`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1
    1 row in set (0.00 sec)
    
    mysql> insert into under99color (academy) values
        -> ('Under 10\'s Blue'),('Under 10\'s Green'),('Under 11\'s Red'),
        -> ('Under 11\'s White'),('Under 13\'s Blue'),('Under 13\'s Red'),
        -> ('Under 13\'s White'),('Under 14\'s Blue'),('Under 15\'s Blue'),
        -> ('Under 15\'s Red'),('Under 15\'s White'),('Under 16\'s Red'),
        -> ('Under 18\'s Blue'),('Under 18\'s Red'),('Under 7\'s'),
        -> ('Under 8\'s Red'),('Under 9\`s Red');
    Query OK, 17 rows affected (0.00 sec)
    Records: 17  Duplicates: 0  Warnings: 0
    
    mysql> select academy from under99color
        -> ORDER BY REPLACE(Academy,'Under ','') + 0,Academy;
    +------------------+
    | academy          |
    +------------------+
    | Under 7's        |
    | Under 8's Red    |
    | Under 9`s Red    |
    | Under 10's Blue  |
    | Under 10's Green |
    | Under 11's Red   |
    | Under 11's White |
    | Under 13's Blue  |
    | Under 13's Red   |
    | Under 13's White |
    | Under 14's Blue  |
    | Under 15's Blue  |
    | Under 15's Red   |
    | Under 15's White |
    | Under 16's Red   |
    | Under 18's Blue  |
    | Under 18's Red   |
    +------------------+
    17 rows in set (0.00 sec)
    
    mysql>
    

    Give it a Try !!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have already created a webpart to show the data from list, but I
i have a large list of static data from a server that i load
I have a test list that I am trying to capture data from using
I have looped data from mysql, and it's a pretty long list. What's the
I have a long list of data that I want to display in table
I have made an SQL query from two tables. Everything works good but problem
I have a list of data that looks like the following: // timestep,x_position,y_position 0,4,7
I have a list of data that is a schedule. Each item has a
If I have a list of data in a text file seperated by a
I have some C structures related to a 'list' data structure. They look like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.