How to Sort a Field of a MySQL Table in Ascending Order in PHP


In this article, we will show how you can sort any field of a MySQL in ascending order. This means in alphabetical order for alphabetical characters and in numerical order for number values.

This can be for any column of a table. Putting values in ascending order is important for a wide variety of applications.

Think about a site such as travelocity. After you've entered in the data for the flight you are looking for and the site has processed the data to enter matching flights, you now have a bunch of flights returned to you. You can now order the sites by price, from cheapest to most expensive, by airline name (A-Z), and many different factors. These are applications that sorting a column in ascending order have. They can list a column in the exact order which a user wants to view them by cheapest to most expensive, shortest to longest flight duration, airline name (A-Z), etc.


An example of this is a table below of snack foods, where the table is arranged in order of the price: