After you connect code from the database
You can now fetch the data from it and use the DESC or ASC attribute for the arrangement of the lists that you wanted.
Browse the links below as your reference.
http://www.mysqltutorial.org/php-queryi ... sql-table/
or lean basics from the W3Shools
I hope you can manage it.