Jump to content

Sorting Data


TheGallery

Recommended Posts

Hello again community. My problem has 2 parts. The first part is about the best method to solve it, and the second part is the method i have chosen and some problems that occured. I have a database that stores usernames and tracks their visits in the website. I want to make a page that will show the users either alphabeticaly or by visits. The first question is, what's the best method of sorting them (depending on the choice), should i store them in an array (with the username as key and the visits as value) or i should send commands to sort the database. The question may be stupid but i've heard about database sorting, i don't know if it's for such occasions though. If there is a different, even better way to display the data i'd like to hear it :) I have chosen to store the data in an array, with the usernames as key and the visits as values. I know how to sort arrays according to keys or values, but i need to display the usernames and i don't know how to display the keys Oo.

Link to comment
Share on other sites

When you perform the SQL query, the ORDER BY clause will let you choose which field to sort the results by. If you want them reversed, add the DESC keyword.

SELECT field1,field2 from table ORDER BY field1

SELECT fieldA,fieldA from table ORDER BY fieldB DESC

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...